Class: NormalizeCountry::Country
- Inherits:
-
Object
- Object
- NormalizeCountry::Country
- Defined in:
- lib/normalize_country.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #formats ⇒ Object
-
#initialize(config) ⇒ Country
constructor
A new instance of Country.
- #names ⇒ Object
Constructor Details
#initialize(config) ⇒ Country
Returns a new instance of Country.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/normalize_country.rb', line 48 def initialize(config) raise ArgumentError, "country config must be a hash" unless Hash === config @mapping = {} config.each do |id, value| @mapping[id.to_sym] = Array === value ? value.compact.map { |v| v.squeeze(" ").strip } : value ? value.squeeze(" ").strip : value end end |
Instance Method Details
#[](id) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/normalize_country.rb', line 59 def [](id) id = id.to_s return if id.empty? or id.to_sym == :aliases name = @mapping[id.to_sym] return name.dup if name end |
#formats ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/normalize_country.rb', line 66 def formats @formats ||= begin keys = @mapping.keys keys.delete(:aliases) keys end end |
#names ⇒ Object
74 75 76 |
# File 'lib/normalize_country.rb', line 74 def names @names ||= @mapping.values.flatten.uniq.compact end |