countries_data 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbb1f697b19e871725f709a13aa04b9544a9d8b613e8cb737421641c8e1749a6
4
- data.tar.gz: 413a90d178a542fdaf81c07b73094322c726eca1359c7b7fa96332e9b5d62a9b
3
+ metadata.gz: 4b59b914633ab00f09b6fa82a201f76d40e13c29e9c4437f257605ae9e54738e
4
+ data.tar.gz: 2a38ea3f8cf9738165970bbec99d25ef78147e26f5d1fbd950ab9d2fc1b312c1
5
5
  SHA512:
6
- metadata.gz: 06e5b9208a3a634c819fb9a23378f6f70add7121b1eff348f08de7d84678d814b3dc53fc4e3923ef525e1b60e2ab14d4d3dd9b99ca573cc36d6cf29c0492e1d8
7
- data.tar.gz: c5e3bb3edfff2f1376064be53b57ea1747b44a031f872ffc933b92370f4ccb3c4b1334bc50baf72cf72993f195a5fc499de726dfdd61386f6ed7950934386a57
6
+ metadata.gz: 1c8405656eefaac40d17bbe6a3da082b061396451a1cf032216f461f398f82475ff414c518a43bce273b598beb5263aea887644187c0f59eec25bb5a07254dc5
7
+ data.tar.gz: 441ba62b267b855635ed4003912d4a98a261161c721fce203677d38ff150805709f870001e1e7f94fb28f74d6e5964576eb2c35ef1808081fbe6168cdf65d776
@@ -1,17 +1,17 @@
1
1
  require 'yaml'
2
- require_relative './country'
2
+ require_relative 'country'
3
3
 
4
4
  module CountriesData
5
5
  class Collection
6
- DATA = YAML.safe_load(File.read(File.join(__dir__, 'data.yml')), symbolize_names: true).freeze
6
+ DATA = YAML.safe_load_file(File.join(__dir__, 'data.yml'), symbolize_names: true).freeze
7
7
 
8
8
  COUNTRIES = DATA[:countries].map { |c| Country.new(c) }.freeze
9
9
 
10
- IDS_MAP = COUNTRIES.each_with_index.each_with_object({}) do |(country, index), prev|
10
+ IDS_MAP = COUNTRIES.each_with_index.with_object({}) do |(country, index), prev|
11
11
  prev[country.id] = index
12
12
  end
13
13
 
14
- PHONE_CODES_MAP = COUNTRIES.each_with_index.each_with_object({}) do |(country, index), prev|
14
+ PHONE_CODES_MAP = COUNTRIES.each_with_index.with_object({}) do |(country, index), prev|
15
15
  next prev if country.phone_code.nil?
16
16
 
17
17
  prev[country.phone_code] = [] if prev[country.phone_code].nil?
@@ -24,7 +24,7 @@ module CountriesData
24
24
 
25
25
  def self.find_by_id(id)
26
26
  index = IDS_MAP[id.to_s]
27
- return COUNTRIES[index] unless index.nil?
27
+ COUNTRIES[index] unless index.nil?
28
28
  end
29
29
 
30
30
  def self.find_by_phone_code(phone_code)
@@ -4,6 +4,7 @@ module CountriesData
4
4
  attr_reader :emoji
5
5
  attr_reader :names
6
6
  attr_reader :phone_code
7
+ attr_reader :nationalities
7
8
 
8
9
  PHONE_MIN_LENGTH = 5
9
10
  PHONE_MAX_LENGTH = 14
@@ -15,6 +16,7 @@ module CountriesData
15
16
  @phone_code = data[:phone_code]
16
17
  @phone_min_length = data[:phone_min_length]
17
18
  @phone_max_length = data[:phone_max_length]
19
+ @nationalities = data[:nationalities]
18
20
  end
19
21
 
20
22
  def name(locale)
@@ -28,5 +30,9 @@ module CountriesData
28
30
  def phone_max_length
29
31
  @phone_max_length || PHONE_MAX_LENGTH
30
32
  end
33
+
34
+ def nationality(locale)
35
+ nationalities[locale.to_sym]
36
+ end
31
37
  end
32
38
  end