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.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/normalize_country.rb', line 50 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
61 62 63 64 65 66 |
# File 'lib/normalize_country.rb', line 61 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
68 69 70 71 72 73 74 |
# File 'lib/normalize_country.rb', line 68 def formats @formats ||= begin keys = @mapping.keys keys.delete(:aliases) keys end end |
#names ⇒ Object
76 77 78 |
# File 'lib/normalize_country.rb', line 76 def names @names ||= @mapping.values.flatten.uniq.compact end |