Class: CountryCodes::LookupTable
- Inherits:
-
Object
- Object
- CountryCodes::LookupTable
- Includes:
- Internal::Helpers
- Defined in:
- lib/country_codes/lookup_table.rb
Instance Method Summary collapse
-
#find(term) ⇒ CountryCodes::Country?
Searches for a country that matches a given term.
-
#initialize(locale, indexed_fields) ⇒ LookupTable
constructor
A new instance of LookupTable.
Methods included from Internal::Helpers
included, #pack_seq, #unpack_seq, #unpack_some
Constructor Details
#initialize(locale, indexed_fields) ⇒ LookupTable
Note:
This code is not supposed to be used externally!
Returns a new instance of LookupTable.
16 17 18 |
# File 'lib/country_codes/lookup_table.rb', line 16 def initialize(locale, indexed_fields) @lookup_table = ISOCountryCodes.apply(locale, pack_seq(indexed_fields)) end |
Instance Method Details
#find(term) ⇒ CountryCodes::Country?
Searches for a country that matches a given term. If nothing was found, returns ‘nil`.
25 26 27 28 29 30 31 32 33 |
# File 'lib/country_codes/lookup_table.rb', line 25 def find(term) packed = @lookup_table.lookup(term) java_country = unpack_some(packed) return nil if java_country.nil? Country.new(java_country) end |