Module: RecipeScrapers::Parsers::Chain Private
- Defined in:
- lib/recipe_scrapers/parsers/chain.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Runs the parsers of a field in order until one returns something. A parser returns a hash of the model's attributes, which becomes the model, or nil. A parser that raises, or returns a hash with an unknown key, goes to Configuration#error_tracker, and the next one is tried.
Constant Summary collapse
- FIELDS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%i[ingredients nutrients].freeze
Class Method Summary collapse
- .defaults ⇒ Object private
- .field!(field) ⇒ Object private
- .run(field, parsers, text, language:) ⇒ Object private
Class Method Details
.defaults ⇒ Object
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.
17 18 19 |
# File 'lib/recipe_scrapers/parsers/chain.rb', line 17 def defaults { ingredients: [Ingredients], nutrients: [Nutrients] } end |
.field!(field) ⇒ Object
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.
21 22 23 24 25 |
# File 'lib/recipe_scrapers/parsers/chain.rb', line 21 def field!(field) return field if FIELDS.include?(field) raise ArgumentError, "no parser can be set for #{field.inspect}, only for #{FIELDS.join(", ")}" end |
.run(field, parsers, text, language:) ⇒ Object
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.
27 28 29 30 31 32 33 |
# File 'lib/recipe_scrapers/parsers/chain.rb', line 27 def run(field, parsers, text, language:) parsers.each do |parser| result = attempt(field, parser, text, language) return result unless result.nil? end nil end |