class Openfoodfacts::Additive
Constants
- LOCALE_PATHS
TODO: Add more locales
Public Class Methods
all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN)
click to toggle source
Get additives
# File lib/openfoodfacts/additive.rb, line 18 def all(locale: DEFAULT_LOCALE, domain: DEFAULT_DOMAIN) if path = LOCALE_PATHS[locale] page_url = "https://#{locale}.#{domain}/#{path}" Product.tags_from_page(self, page_url) do |tag| columns = tag.css('td') link = tag.css('a').first attributes = { "name" => link.text.strip, "url" => URI.join(page_url, link.attr('href')).to_s, "products_count" => columns[1].text.to_i } riskiness = columns.last.attr('class') if riskiness attributes["riskiness"] = riskiness[/level_(\d+)/, 1].to_i end new(attributes) end end end
Public Instance Methods
products(page: -1)
click to toggle source
Get products with additive
# File lib/openfoodfacts/additive.rb, line 46 def products(page: -1) Product.from_website_page(url, page: page, products_count: products_count) if url end