Class: RecipeScrapers::Sources::Microdata
- Inherits:
-
Object
- Object
- RecipeScrapers::Sources::Microdata
- Defined in:
- lib/recipe_scrapers/sources/microdata.rb
Constant Summary collapse
- VALUE_ATTRIBUTES =
{ "meta" => "content", "audio" => "src", "embed" => "src", "iframe" => "src", "img" => "src", "source" => "src", "track" => "src", "video" => "src", "a" => "href", "area" => "href", "link" => "href", "object" => "data", "data" => "value", "meter" => "value", "time" => "datetime" }.freeze
- INLINE =
%w[ a abbr b bdi bdo big cite code data del dfn em font i img ins kbd label link mark meta q s samp small span strong sub sup svg time tt u var wbr ].freeze
Instance Method Summary collapse
-
#initialize(document) ⇒ Microdata
constructor
A new instance of Microdata.
- #person(id) ⇒ Object
- #rating(id) ⇒ Object
- #recipe ⇒ Object
- #website_name ⇒ Object
Constructor Details
#initialize(document) ⇒ Microdata
Returns a new instance of Microdata.
22 23 24 25 |
# File 'lib/recipe_scrapers/sources/microdata.rb', line 22 def initialize(document) @nodes = roots(document).flat_map { |element| flatten(item_for(element)) } @by_id = @nodes.select { |node| node["@id"] }.to_h { |node| [node["@id"], node] } end |
Instance Method Details
#person(id) ⇒ Object
28 |
# File 'lib/recipe_scrapers/sources/microdata.rb', line 28 def person(id) = entity(id, "Person") |
#rating(id) ⇒ Object
29 |
# File 'lib/recipe_scrapers/sources/microdata.rb', line 29 def (id) = entity(id, "AggregateRating") |
#recipe ⇒ Object
27 |
# File 'lib/recipe_scrapers/sources/microdata.rb', line 27 def recipe = @recipe ||= node_of_type("Recipe") |