Module: RecipeScrapers::Scraper::ParsedFields
- Included in:
- RecipeScrapers::Scraper
- Defined in:
- lib/recipe_scrapers/scraper/parsed_fields.rb
Overview
The fields that split text into value objects, with the parsers Configuration#parsers holds.
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
- .included(scraper) ⇒ void private
Instance Method Summary collapse
-
#parsed_ingredients ⇒ Array<Models::Ingredient>?
Every line of Models::Recipe#ingredients, in the same order, split into an amount, a unit and a name.
-
#parsed_nutrients ⇒ Array<Models::Nutrient>?
Every entry of Models::Recipe#nutrients, in the order the page lists them, split into a name, a unit and an amount.
Class Method Details
.included(scraper) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
11 12 13 |
# File 'lib/recipe_scrapers/scraper/parsed_fields.rb', line 11 def self.included(scraper) scraper.extend(ClassMethods) end |
Instance Method Details
#parsed_ingredients ⇒ Array<Models::Ingredient>?
Every line of Models::Recipe#ingredients, in the same order, split into an amount, a unit and a name.
36 37 38 39 |
# File 'lib/recipe_scrapers/scraper/parsed_fields.rb', line 36 def parsed_ingredients spoken = language ingredients&.map { |line| parse(:ingredients, line, spoken) } end |
#parsed_nutrients ⇒ Array<Models::Nutrient>?
Every entry of Models::Recipe#nutrients, in the order the page lists them, split into a name, a unit and an amount. The name is the key the page uses. A value with no number is left out.
42 43 44 45 46 47 48 49 |
# File 'lib/recipe_scrapers/scraper/parsed_fields.rb', line 42 def parsed_nutrients spoken = language parsed = nutrients.to_h.filter_map do |name, text| nutrient = parse(:nutrients, text, spoken) nutrient && (nutrient.name ? nutrient : nutrient.with(name: name)) end parsed.empty? ? nil : parsed end |