Class: ISO3166::Country
Constant Summary
ISO3166::CountryClassMethods::FIND_BY_REGEX
Constants included
from Emoji
Emoji::CODE_POINTS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
[], all, all_names_with_codes, all_translated, codes, find_all_by, method_missing, new, respond_to_missing?, search, strip_accents, translations
Methods included from Emoji
#emoji_flag
Constructor Details
#initialize(country_data) ⇒ Country
Returns a new instance of Country.
19
20
21
22
|
# File 'lib/countries/country.rb', line 19
def initialize(country_data)
@country_data_or_code = country_data
reload
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5
6
7
|
# File 'lib/countries/country.rb', line 5
def data
@data
end
|
Class Method Details
.demongoize(alpha2) ⇒ Object
16
17
18
|
# File 'lib/countries/mongoid.rb', line 16
def demongoize(alpha2)
new(alpha2)
end
|
.evolve(country) ⇒ Object
20
21
22
|
# File 'lib/countries/mongoid.rb', line 20
def evolve(country)
mongoize(country)
end
|
.mongoize(country) ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/countries/mongoid.rb', line 8
def mongoize(country)
if country.is_a?(self) && !country.data.nil?
country.alpha2
elsif send(:valid_alpha2?, country)
new(country).alpha2
end
end
|
Instance Method Details
#<=>(other) ⇒ Object
46
47
48
|
# File 'lib/countries/country.rb', line 46
def <=>(other)
to_s <=> other.to_s
end
|
#==(other) ⇒ Object
34
35
36
|
# File 'lib/countries/country.rb', line 34
def ==(other)
other.respond_to?(:alpha2) && other.alpha2 == alpha2
end
|
#currency ⇒ Object
50
51
52
|
# File 'lib/countries/country.rb', line 50
def currency
Money::Currency.find(data['currency_code'])
end
|
#eql?(other) ⇒ Boolean
38
39
40
|
# File 'lib/countries/country.rb', line 38
def eql?(other)
self == other
end
|
#hash ⇒ Object
42
43
44
|
# File 'lib/countries/country.rb', line 42
def hash
[alpha2, alpha3].hash
end
|
#in_eea? ⇒ Boolean
70
71
72
|
# File 'lib/countries/country.rb', line 70
def in_eea?
data['eea_member'].nil? ? false : data['eea_member']
end
|
#in_eu? ⇒ Boolean
66
67
68
|
# File 'lib/countries/country.rb', line 66
def in_eu?
data['eu_member'].nil? ? false : data['eu_member']
end
|
#local_name ⇒ Object
94
95
96
|
# File 'lib/countries/country.rb', line 94
def local_name
@local_name ||= local_names.first
end
|
#local_names ⇒ Object
TODO: Looping through locale langs could be be very slow across multiple countries
87
88
89
90
91
92
|
# File 'lib/countries/country.rb', line 87
def local_names
ISO3166.configuration.locales = (ISO3166.configuration.locales + languages.map(&:to_sym)).uniq
reload
@local_names ||= languages.map { |language| translations[language] }
end
|
#reload ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/countries/country.rb', line 98
def reload
@data = if @country_data_or_code.is_a?(Hash)
@country_data_or_code
else
ISO3166::Data.new(@country_data_or_code).call
end
end
|
#subdivisions ⇒ Object
Also known as:
states
58
59
60
61
62
|
# File 'lib/countries/country.rb', line 58
def subdivisions
@subdivisions ||= subdivision_data.inject({}) do |hash, (k, v)|
hash.merge(k => Subdivision.new(v))
end
end
|
#subdivisions? ⇒ Boolean
54
55
56
|
# File 'lib/countries/country.rb', line 54
def subdivisions?
File.exist?(subdivision_file_path)
end
|
#to_s ⇒ Object
74
75
76
|
# File 'lib/countries/country.rb', line 74
def to_s
data['name']
end
|
#translated_names ⇒ Object
78
79
80
|
# File 'lib/countries/country.rb', line 78
def translated_names
data['translations'].values
end
|
#translation(locale = 'en') ⇒ Object
82
83
84
|
# File 'lib/countries/country.rb', line 82
def translation(locale = 'en')
data['translations'][locale.to_s.downcase]
end
|
#valid? ⇒ Boolean
24
25
26
|
# File 'lib/countries/country.rb', line 24
def valid?
!(data.nil? || data.empty?)
end
|