class Openfoodfacts::Locale

Constants

GLOBAL

Public Class Methods

all(domain: DEFAULT_DOMAIN) click to toggle source

Get locales

# File lib/openfoodfacts/locale.rb, line 12
def all(domain: DEFAULT_DOMAIN)
  path = 'cgi/i18n/countries.pl?_type=query'
  url = "https://#{GLOBAL}.#{domain}/#{path}"
  json = URI.open(url).read
  hash = JSON.parse(json)

  hash.map { |pair|
    locale_from_pair(pair, domain: domain)
  }.compact
end
locale_from_pair(pair, domain: DEFAULT_DOMAIN) click to toggle source

Return locale from pair

# File lib/openfoodfacts/locale.rb, line 32
def locale_from_pair(pair, domain: DEFAULT_DOMAIN)
  code = pair.first
  {
    "name" => pair.last.strip,
    "code" => code,
    "url" => "https://#{code}.#{domain}"
  } if code
end