list_of_countries 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "list_of_countries/country.rb"
5
+ require "list_of_countries/version"
6
+
7
+ module ListOfCountries
8
+ def self.all
9
+ @all ||= begin
10
+ path = File.expand_path("../../data/countries/countries.json", __FILE__)
11
+ file = File.open(path, "r")
12
+ JSON.load(file).map do |data|
13
+ Country.new(data)
14
+ end.freeze
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "list_of_countries/name"
4
+ require "list_of_countries/demonyms"
5
+
6
+ module ListOfCountries
7
+ class Country
8
+ attr_reader :name
9
+ attr_reader :demonyms
10
+ attr_reader :languages
11
+ attr_reader :region
12
+ attr_reader :subregion
13
+
14
+ def initialize(data)
15
+ @name = Name.new(data.fetch("name"))
16
+ @demonyms = Demonyms.new(fetch_demonyms(data))
17
+ @languages = data.fetch("languages").values
18
+ @region = data.fetch("region")
19
+ @subregion = data.fetch("subregion")
20
+ end
21
+
22
+ private
23
+
24
+ def fetch_demonyms(data)
25
+ demonym = data["demonym"]
26
+ if demonym
27
+ return {
28
+ "eng" => {
29
+ "f" => demonym,
30
+ "m" => demonym,
31
+ },
32
+ }
33
+ end
34
+
35
+ demonyms = data["demonyms"]
36
+ if demonyms
37
+ return demonyms
38
+ end
39
+
40
+ raise KeyError, %q{keys not found: "demonym" or "demonyms"}
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ListOfCountries
4
+ class Demonyms
5
+ attr_reader :female
6
+ attr_reader :male
7
+
8
+ def initialize(data)
9
+ eng = data.fetch("eng")
10
+ @female = eng.fetch("f")
11
+ @male = eng.fetch("m")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ListOfCountries
4
+ class Name
5
+ attr_reader :common
6
+ attr_reader :official
7
+
8
+ def initialize(data)
9
+ @common = data.fetch("common")
10
+ @official = data.fetch("official")
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ListOfCountries
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/list_of_countries/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "list_of_countries"
5
+ spec.version = ListOfCountries::VERSION
6
+ spec.authors = ["Tate Johnson"]
7
+ spec.email = ["tate@tatey.com"]
8
+
9
+ spec.summary = %q{List of countries}
10
+ spec.description = %q{List of countries}
11
+ spec.homepage = "https://github.com/tatey/list_of_countries"
12
+ spec.license = "ODbL"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|data)/}) }
22
+ end
23
+ spec.files << "data/countries/countries.json"
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: list_of_countries
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tate Johnson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: List of countries
14
+ email:
15
+ - tate@tatey.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".gitmodules"
22
+ - CODE_OF_CONDUCT.md
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - data/countries/countries.json
30
+ - lib/list_of_countries.rb
31
+ - lib/list_of_countries/country.rb
32
+ - lib/list_of_countries/demonyms.rb
33
+ - lib/list_of_countries/name.rb
34
+ - lib/list_of_countries/version.rb
35
+ - list_of_countries.gemspec
36
+ homepage: https://github.com/tatey/list_of_countries
37
+ licenses:
38
+ - ODbL
39
+ metadata:
40
+ homepage_uri: https://github.com/tatey/list_of_countries
41
+ source_code_uri: https://github.com/tatey/list_of_countries
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.3.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.0.3
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: List of countries
61
+ test_files: []