Class: Openfoodfacts::ProductState

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/openfoodfacts/product_state.rb

Constant Summary collapse

LOCALE_PATHS =

TODO: Add more locales

{
  'fr' => 'etats',
  'uk' => 'states',
  'us' => 'states',
  'world' => 'states'
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN) ⇒ Object

Get product states


18
19
20
21
22
# File 'lib/openfoodfacts/product_state.rb', line 18

def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
  if path = LOCALE_PATHS[locale]
    Product.tags_from_page(self, "http://#{locale}.#{domain}/#{path}")
  end
end

Instance Method Details

#products(page: -1)) ⇒ Object

Get products with state


28
29
30
# File 'lib/openfoodfacts/product_state.rb', line 28

def products(page: -1)
  Product.from_website_page(url, page: page, products_count: products_count) if url
end