Module: Atlasq::Data

Defined in:
lib/atlasq/data.rb

Class Method Summary collapse

Class Method Details

.all_countriesArray<String>

Returns ISO3166 2 letter country codes.

Returns:

  • (Array<String>)

    ISO3166 2 letter country codes



22
23
24
# File 'lib/atlasq/data.rb', line 22

def self.all_countries
  Cache.get("list/all_countries.json")
end

.all_currenciesHash<String, Array<String>>

Returns ISO4127 3 letter currency code to ISO3166 2 letter country codes.

Returns:

  • (Hash<String, Array<String>>)

    ISO4127 3 letter currency code to ISO3166 2 letter country codes



52
53
54
# File 'lib/atlasq/data.rb', line 52

def self.all_currencies
  Cache.get("search_index/countries_by_currency.json")
end

.all_languagesHash<String, Array<String>>

Returns ISO639 2 letter language code to ISO3166 2 letter country codes.

Returns:

  • (Hash<String, Array<String>>)

    ISO639 2 letter language code to ISO3166 2 letter country codes



73
74
75
# File 'lib/atlasq/data.rb', line 73

def self.all_languages
  Cache.get("search_index/countries_by_language.json")
end

.all_subregionsArray<String>

Returns:

  • (Array<String>)


27
28
29
30
31
32
33
# File 'lib/atlasq/data.rb', line 27

def self.all_subregions
  subregions = Cache.get("list/all_subregions.json")

  Cache
    .get("search_index/countries_by_region.json")
    .slice(*subregions)
end

.countries_by_currencies(terms) ⇒ Hash<String, Array<String>>

Returns ISO4127 3 letter currency code to ISO3166 2 letter country codes.

Parameters:

  • terms (String, Array<String>)

    search terms

Returns:

  • (Hash<String, Array<String>>)

    ISO4127 3 letter currency code to ISO3166 2 letter country codes



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/atlasq/data.rb', line 37

def self.countries_by_currencies(terms)
  terms = Array(terms)
  currency_codes = Cache
    .get("search_index/direct_match_currency.json")
    .values_at(*terms)
    .compact

  return if currency_codes.empty?

  Cache
    .get("search_index/countries_by_currency.json")
    .slice(*currency_codes)
end

.countries_by_languages(terms) ⇒ Hash<String, Array<String>>

Returns ISO639 2 letter language code to ISO3166 2 letter country codes.

Parameters:

  • terms (String, Array<String>)

    search terms

Returns:

  • (Hash<String, Array<String>>)

    ISO639 2 letter language code to ISO3166 2 letter country codes



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/atlasq/data.rb', line 58

def self.countries_by_languages(terms)
  terms = Array(terms)
  languages = Cache
    .get("search_index/direct_match_language.json")
    .values_at(*terms)
    .compact

  return if languages.empty?

  Cache
    .get("search_index/countries_by_language.json")
    .slice(*languages)
end

.countries_by_region(term) ⇒ Array<String>?

Returns ISO3166 2 letter country codes.

Parameters:

  • term (String)

    search term

Returns:

  • (Array<String>, nil)

    ISO3166 2 letter country codes



15
16
17
18
19
# File 'lib/atlasq/data.rb', line 15

def self.countries_by_region(term)
  Cache
    .get("search_index/countries_by_region.json")
    .dig(term)
end

.country(term) ⇒ String?

Returns ISO3166 2 letter country code.

Parameters:

  • term (String)

    search term

Returns:

  • (String, nil)

    ISO3166 2 letter country code



7
8
9
10
11
# File 'lib/atlasq/data.rb', line 7

def self.country(term)
  Cache
    .get("search_index/direct_match_country.json")
    .dig(term)
end