Class: CountryCodes::LookupTable

Inherits:
Object
  • Object
show all
Includes:
Internal::Helpers
Defined in:
lib/country_codes/lookup_table.rb

Instance Method Summary collapse

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`.

Parameters:

  • term (String)

    Search term

Returns:



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