Module: NormalizeCountry
- Defined in:
- lib/normalize_country.rb,
lib/normalize_country/scanner.rb
Defined Under Namespace
Classes: Country, Scanner, Tokenizer
Constant Summary
collapse
- VERSION =
"0.3.2"
- Countries =
{}
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.to ⇒ Object
12
13
14
|
# File 'lib/normalize_country.rb', line 12
def to
@to ||= :iso_name
end
|
Class Method Details
.convert(name, options = {}) ⇒ Object
20
21
22
23
24
|
# File 'lib/normalize_country.rb', line 20
def convert(name, options = {})
country = country_for(name)
return unless country
country[ options[:to] || to ]
end
|
16
17
18
|
# File 'lib/normalize_country.rb', line 16
def formats
@formats ||= Countries.values.flat_map(&:formats).uniq end
|
.to_a(name = to) ⇒ Object
26
27
28
29
|
# File 'lib/normalize_country.rb', line 26
def to_a(name = to)
return [] if Countries.values.find { |c| c[name] }.nil? Countries.values.uniq.map { |c| c[name] }.compact.sort { |a, b| a <=> b }
end
|
.to_h(key, options = {}) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/normalize_country.rb', line 31
def to_h(key, options = {})
value = options[:to] || to
countries = Countries.values
return {} unless [ key, value ].all? { |v| countries.first[v] }
hash = {}
countries.each { |c| hash[ c[key] ] = c[value] }
hash
end
|