Class: ISO3166::Country
- Inherits:
-
Object
- Object
- ISO3166::Country
- Extended by:
- ConversionMethods, CountryClassMethods, CountryFinderMethods
- Includes:
- CountrySubdivisionMethods, Emoji, TimezoneExtensions
- Defined in:
- lib/countries/country.rb,
lib/countries/mongoid.rb
Direct Known Subclasses
Constant Summary
Constants included from CountryFinderMethods
ISO3166::CountryFinderMethods::FIND_BY_REGEX, ISO3166::CountryFinderMethods::SEARCH_TERM_FILTER_REGEX
Constants included from Emoji
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
-
.demongoize(alpha2) ⇒ Object
Get the object as it was stored with Mongoid, and instantiate an
ISO3166::Country
. -
.evolve(country) ⇒ Object
Convert an
ISO3166::Country
to the data that is stored by Mongoid. -
.mongoize(country) ⇒ Object
Convert an
ISO3166::Country
to the data that is stored by Mongoid.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#common_name ⇒ String
The “common name” of this Country in English.
- #eql?(other) ⇒ Boolean
-
#gdpr_compliant? ⇒ Boolean
true
if this country is a member of the European Economic Area or it is UK. - #hash ⇒ Object
-
#in_eea? ⇒ Boolean
true
if this country is a member of the European Economic Area. -
#in_esm? ⇒ Boolean
true
if this country is a member of the European Single Market. -
#in_eu? ⇒ Boolean
true
if this country is a member of the European Union. -
#in_eu_vat? ⇒ Boolean
true
if this country is a member of the EU VAT Area. -
#in_g20? ⇒ Boolean
true
if this country is a member of the G20. -
#in_g7? ⇒ Boolean
true
if this country is a member of the G7. -
#initialize(country_data) ⇒ Country
constructor
A new instance of Country.
-
#local_name ⇒ String
The name for this Country, in this Country’s locale.
-
#local_names ⇒ Array<String>
TThe list of names for this Country, in this Country’s locales.
- #mongoize ⇒ Object
-
#postal_code_format ⇒ String
The regex for valid postal codes in this Country.
- #to_s ⇒ Object
-
#translated_names ⇒ Array<String>
The list of names for this Country in all loaded locales.
-
#translation(locale = 'en') ⇒ String
The name of this Country in the selected locale.
- #valid? ⇒ Boolean
- #zip_format ⇒ Object
Methods included from CountryClassMethods
all, all_names_with_codes, all_translated, codes, collect_countries_with, collect_likely_countries_by_subdivision_name, new, pluck, translations
Methods included from ConversionMethods
from_alpha2_to_alpha3, from_alpha3_to_alpha2
Methods included from CountryFinderMethods
[], find_all_by, method_missing, respond_to_missing?, search
Methods included from TimezoneExtensions
Methods included from CountrySubdivisionMethods
#find_subdivision_by_name, #humanized_subdivision_types, #subdivision_for_string?, #subdivision_names, #subdivision_names_with_codes, #subdivision_types, #subdivisions, #subdivisions?, #subdivisions_of_types
Methods included from Emoji
Constructor Details
#initialize(country_data) ⇒ Country
Returns a new instance of Country.
24 25 26 27 |
# File 'lib/countries/country.rb', line 24 def initialize(country_data) @country_data_or_code = country_data reload end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/countries/country.rb', line 10 def data @data end |
Class Method Details
.demongoize(alpha2) ⇒ Object
Get the object as it was stored with Mongoid, and instantiate an ISO3166::Country
.
20 21 22 |
# File 'lib/countries/mongoid.rb', line 20 def demongoize(alpha2) new(alpha2) end |
.evolve(country) ⇒ Object
Convert an ISO3166::Country
to the data that is stored by Mongoid.
25 26 27 |
# File 'lib/countries/mongoid.rb', line 25 def evolve(country) mongoize(country) end |
.mongoize(country) ⇒ Object
Convert an ISO3166::Country
to the data that is stored by Mongoid.
11 12 13 14 15 16 17 |
# File 'lib/countries/mongoid.rb', line 11 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
51 52 53 |
# File 'lib/countries/country.rb', line 51 def <=>(other) to_s <=> other.to_s end |
#==(other) ⇒ Object
39 40 41 |
# File 'lib/countries/country.rb', line 39 def ==(other) other.respond_to?(:alpha2) && other.alpha2 == alpha2 end |
#common_name ⇒ String
Returns the “common name” of this Country in English.
111 112 113 114 |
# File 'lib/countries/country.rb', line 111 def common_name ISO3166.configuration.locales = ISO3166.configuration.locales.append(:en).uniq translation('en') end |
#eql?(other) ⇒ Boolean
43 44 45 |
# File 'lib/countries/country.rb', line 43 def eql?(other) self == other end |
#gdpr_compliant? ⇒ Boolean
true
if this country is a member of the European Economic Area or it is UK
71 72 73 |
# File 'lib/countries/country.rb', line 71 def gdpr_compliant? data['eea_member'] || alpha2 == 'GB' end |
#hash ⇒ Object
47 48 49 |
# File 'lib/countries/country.rb', line 47 def hash [alpha2, alpha3].hash end |
#in_eea? ⇒ Boolean
true
if this country is a member of the European Economic Area.
76 77 78 |
# File 'lib/countries/country.rb', line 76 def in_eea? data['eea_member'].nil? ? false : data['eea_member'] end |
#in_esm? ⇒ Boolean
true
if this country is a member of the European Single Market.
81 82 83 |
# File 'lib/countries/country.rb', line 81 def in_esm? data['esm_member'].nil? ? in_eea? : data['esm_member'] end |
#in_eu? ⇒ Boolean
true
if this country is a member of the European Union.
56 57 58 |
# File 'lib/countries/country.rb', line 56 def in_eu? data['eu_member'].nil? ? false : data['eu_member'] end |
#in_eu_vat? ⇒ Boolean
true
if this country is a member of the EU VAT Area.
86 87 88 |
# File 'lib/countries/country.rb', line 86 def in_eu_vat? data['euvat_member'].nil? ? in_eu? : data['euvat_member'] end |
#in_g20? ⇒ Boolean
true
if this country is a member of the G20.
66 67 68 |
# File 'lib/countries/country.rb', line 66 def in_g20? data['g20_member'].nil? ? false : data['g20_member'] end |
#in_g7? ⇒ Boolean
true
if this country is a member of the G7.
61 62 63 |
# File 'lib/countries/country.rb', line 61 def in_g7? data['g7_member'].nil? ? false : data['g7_member'] end |
#local_name ⇒ String
Returns The name for this Country, in this Country’s locale.
125 126 127 |
# File 'lib/countries/country.rb', line 125 def local_name @local_name ||= local_names.first end |
#local_names ⇒ Array<String>
Returns TThe list of names for this Country, in this Country’s locales.
117 118 119 120 121 122 |
# File 'lib/countries/country.rb', line 117 def local_names ISO3166.configuration.locales = (ISO3166.configuration.locales + languages.map(&:to_sym)).uniq reload @local_names ||= languages.map { |language| translations[language] } end |
#mongoize ⇒ Object
5 6 7 |
# File 'lib/countries/mongoid.rb', line 5 def mongoize ISO3166::Country.mongoize(self) end |
#postal_code_format ⇒ String
Returns The regex for valid postal codes in this Country.
91 92 93 |
# File 'lib/countries/country.rb', line 91 def postal_code_format "\\A#{data['postal_code_format']}\\Z" if postal_code end |
#to_s ⇒ Object
95 96 97 |
# File 'lib/countries/country.rb', line 95 def to_s data['iso_short_name'] end |
#translated_names ⇒ Array<String>
Returns the list of names for this Country in all loaded locales.
100 101 102 |
# File 'lib/countries/country.rb', line 100 def translated_names data['translations'].values.compact end |
#translation(locale = 'en') ⇒ String
Returns the name of this Country in the selected locale.
106 107 108 |
# File 'lib/countries/country.rb', line 106 def translation(locale = 'en') data['translations'][locale.to_s.downcase] end |
#valid? ⇒ Boolean
29 30 31 |
# File 'lib/countries/country.rb', line 29 def valid? !(data.nil? || data.empty?) end |
#zip_format ⇒ Object
36 |
# File 'lib/countries/country.rb', line 36 alias zip_format postal_code_format |