Class: RecipeScrapers::Sources::Declared
- Inherits:
-
Object
- Object
- RecipeScrapers::Sources::Declared
- Defined in:
- lib/recipe_scrapers/sources/declared.rb
Constant Summary collapse
- LIST_MARKER =
/\A(?:[-–*•]|\d+[.)])\s+/
Instance Method Summary collapse
- #headings_among_rows ⇒ Object
-
#initialize(document, declaration) ⇒ Declared
constructor
A new instance of Declared.
- #rows(field) ⇒ Object
- #rule(field) ⇒ Object
- #text(field) ⇒ Object
Constructor Details
#initialize(document, declaration) ⇒ Declared
Returns a new instance of Declared.
8 9 10 11 |
# File 'lib/recipe_scrapers/sources/declared.rb', line 8 def initialize(document, declaration) @document = document @declaration = declaration end |
Instance Method Details
#headings_among_rows ⇒ Object
32 33 34 35 36 37 |
# File 'lib/recipe_scrapers/sources/declared.rb', line 32 def headings_among_rows found = rule(:ingredient_groups) return [] if found.nil? || found[:item] @document.css(found[:heading]).filter_map { |heading| Text.normalize(Text.content(heading)) } end |
#rows(field) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/recipe_scrapers/sources/declared.rb', line 24 def rows(field) found = rule(field) return nil if found.nil? || found[:rows].nil? lines = @document.css(found[:rows]).flat_map { |node| row_lines(readable(node, found[:skip]), found[:split]) } lines.empty? ? nil : lines end |
#rule(field) ⇒ Object
13 14 15 |
# File 'lib/recipe_scrapers/sources/declared.rb', line 13 def rule(field) @declaration&.rule(field) end |
#text(field) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/recipe_scrapers/sources/declared.rb', line 17 def text(field) selector = rule(field)&.fetch(:selector, nil) return nil if selector.nil? Text.normalize(Text.content(@document.at_css(selector))) end |