Class: Openbeautyfacts::Locale
- Inherits:
-
String
- Object
- String
- Openbeautyfacts::Locale
- Defined in:
- lib/openbeautyfacts/locale.rb
Constant Summary collapse
- GLOBAL =
'world'
Class Method Summary collapse
-
.all(domain: DEFAULT_DOMAIN) ⇒ Object
Get locales.
-
.locale_from_link(link) ⇒ Object
Return locale from link.
-
.locale_from_option(option, domain: DEFAULT_DOMAIN) ⇒ Object
Return locale from option.
Class Method Details
.all(domain: DEFAULT_DOMAIN) ⇒ Object
Get locales
10 11 12 13 14 15 16 17 18 |
# File 'lib/openbeautyfacts/locale.rb', line 10 def all(domain: DEFAULT_DOMAIN) url = "https://#{domain}/" body = open(url).read dom = Nokogiri.parse(body) dom.css('#select_country option').map { |option| locale_from_option(option, domain: domain) }.compact end |
.locale_from_link(link) ⇒ Object
Return locale from link
22 23 24 25 |
# File 'lib/openbeautyfacts/locale.rb', line 22 def locale_from_link(link) locale = link[/^https?:\/\/([^.]+)\./i, 1] locale unless locale.nil? || locale == 'static' end |
.locale_from_option(option, domain: DEFAULT_DOMAIN) ⇒ Object
Return locale from option
29 30 31 32 33 34 35 36 |
# File 'lib/openbeautyfacts/locale.rb', line 29 def locale_from_option(option, domain: DEFAULT_DOMAIN) value = option.attr('value') { "name" => option.text.strip, "code" => value, "url" => "https://#{value}.#{domain}" } if value end |