{"id":23244801,"url":"https://github.com/frodsan/countries","last_synced_at":"2025-04-06T00:16:57.690Z","repository":{"id":145874831,"uuid":"477429333","full_name":"frodsan/countries","owner":"frodsan","description":"Ruby code exercise","archived":false,"fork":false,"pushed_at":"2022-04-03T19:29:17.000Z","size":160,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-12T06:24:32.323Z","etag":null,"topics":["restcountries","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frodsan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-03T18:26:09.000Z","updated_at":"2022-04-03T18:30:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"04fb7765-a1fc-444e-9641-a1d0497513d7","html_url":"https://github.com/frodsan/countries","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frodsan%2Fcountries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frodsan%2Fcountries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frodsan%2Fcountries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frodsan%2Fcountries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frodsan","download_url":"https://codeload.github.com/frodsan/countries/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415969,"owners_count":20935387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["restcountries","ruby"],"created_at":"2024-12-19T07:11:15.813Z","updated_at":"2025-04-06T00:16:57.668Z","avatar_url":"https://github.com/frodsan.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# countries\n\nCode exercise to build a simple command line tool that fetches the [REST countries API](https://restcountries.com).\n\n![example](/doc/example.gif)\n\n## Prerequisites\n\n- Ruby 3.1.1\n- Bundler\n\n## Installation\n\nInstall dependencies with:\n\n```\n$ bundle install\n```\n\n## Problem statement\n\n1. Fetch a list of countries with metadata using the [REST countries API](https://restcountries.com).\n\n2. Process and display the data accordingly:\n      - List countries in a table\n      - Show columns: Name, Region, Area, Population\n      - Format the area in square metric miles, without decimals (example, for Norway “125020”)\n      - Format the population in millions with one decimal (example, for Norway “5.2”)\n      - Input option for visualization: sort by one of name, population or area\n      - Summary at the end: Show the population average from all the countries, and also the countries with smallest and biggest area.\n      - List languages with the countries that speak it in a table\n      - Show columns: Language, Countries[], Population\n\n## Solution\n\nI have made a CLI in Ruby that fetches and displays data from [REST countries API](https://restcountries.com).\n\n#### Usage\n\n```\nUSAGE\n  $ bin/countries [OPTIONS]\n\nOPTIONS\n  -f condition value   filter countries by the specified conditions.\n                       [conditions: name, region, subregion, lang]\n\n  -s condition         sort countries by `condition` in ascending order.\n                       [conditions: name (default), region, area, population]\n```\n\n#### Examples\n\n- Find countries where German is the official language and sort them by population:\n\n      $ bin/countries -f lang german -s population\n      +-------------------------------------------------------------------------------+\n      |                               Countries Summary                               |\n      +------------------------------+--------+------------+--------------------------+\n      | Name                         | Region | Area (mi²) | Population (in millions) |\n      +------------------------------+--------+------------+--------------------------+\n      | Liechtenstein                | Europe |         61 |                     0.0M |\n      | Luxembourg                   | Europe |        998 |                     0.6M |\n      | Namibia                      | Africa |     318770 |                     2.5M |\n      | Belgium                      | Europe |      11786 |                    11.6M |\n      | Germany                      | Europe |     137881 |                    83.2M |\n      +------------------------------+--------+------------+--------------------------+\n      | Population average           |        |            |                    19.6M |\n      +------------------------------+--------+------------+--------------------------+\n      | Smallest area: Liechtenstein | Europe |         61 |                     0.0M |\n      | Biggest area: Namibia        | Africa | 318770     |                     2.5M |\n      +------------------------------+--------+------------+--------------------------+\n\n- Find countries whose of their names include 'fr' and sort them by area:\n\n      $ bin/countries -f name fr -s area\n      +-----------------------------------------------------------------------------------------+\n      |                                    Countries Summary                                    |\n      +-------------------------------------+-----------+------------+--------------------------+\n      | Name                                | Region    | Area (mi²) | Population (in millions) |\n      +-------------------------------------+-----------+------------+--------------------------+\n      | Saint Martin                        | Americas  |         20 |                     0.0M |\n      | French Polynesia                    | Oceania   |       1608 |                     0.3M |\n      | French Southern and Antarctic Lands | Antarctic |       2991 |                     0.0M |\n      | France                              | Europe    |     213009 |                    67.4M |\n      | Central African Republic            | Africa    |     240534 |                     4.8M |\n      | South Africa                        | Africa    |     471442 |                    59.3M |\n      +-------------------------------------+-----------+------------+--------------------------+\n      | Population average                  |           |            |                    22.0M |\n      +-------------------------------------+-----------+------------+--------------------------+\n      | Smallest area: Saint Martin         | Americas  |         20 |                     0.0M |\n      | Biggest area: South Africa          | Africa    | 471442     |                    59.3M |\n      +-------------------------------------+-----------+------------+--------------------------+\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrodsan%2Fcountries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrodsan%2Fcountries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrodsan%2Fcountries/lists"}