Module: RecipeScrapers::Parsers::Nutrients
- Defined in:
- lib/recipe_scrapers/parsers/nutrients.rb
Overview
The bundled parser of nutrient values. It reads the first number and the word after it, and drops text in parentheses. Mass and energy units are written as symbols, so "grams" and "г" become "g" and "calories" becomes "kcal".
Class Method Summary collapse
-
.call(text) ⇒ Models::Nutrient?
Without a name, which Models::Recipe#parsed_nutrients fills in.
Class Method Details
.call(text) ⇒ Models::Nutrient?
Returns without a name, which Models::Recipe#parsed_nutrients fills in. Nil when the value has no number.
30 31 32 33 34 35 |
# File 'lib/recipe_scrapers/parsers/nutrients.rb', line 30 def call(text, **) match = text.to_s.gsub(PARENTHESES, " ").match(MEASURE) return nil if match.nil? Models::Nutrient.new(amount: Quantity.total(match[:amount]), unit: unit(match[:unit])) end |