Class: Hangry::Parsers::NonStandard::EatingWellParser

Inherits:
SchemaOrgRecipeParser show all
Defined in:
lib/hangry/parsers/non_standard/eating_well_parser.rb

Instance Attribute Summary

Attributes inherited from RecipeParser

#nokogiri_doc, #nutrition_ast, #recipe, #recipe_ast, #recipe_html

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SchemaOrgRecipeParser

ingredient_itemprop, nutrition_selector

Methods inherited from RecipeParser

canonical_url_matches_domain?, #initialize, #parse

Constructor Details

This class inherits a constructor from Hangry::RecipeParser

Class Method Details

.can_parse?(html) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/hangry/parsers/non_standard/eating_well_parser.rb', line 10

def self.can_parse?(html)
  canonical_url_matches_domain?(html, 'eatingwell.com')
end

.root_selectorObject



6
7
8
# File 'lib/hangry/parsers/non_standard/eating_well_parser.rb', line 6

def self.root_selector
  '[itemtype="http://schema.org/recipe"]'
end

Instance Method Details

#parse_instructionsObject



14
15
16
# File 'lib/hangry/parsers/non_standard/eating_well_parser.rb', line 14

def parse_instructions
  nodes_with_itemprop(:recipeinstructions).map(&:content).join("\n")
end

#parse_nutritionObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hangry/parsers/non_standard/eating_well_parser.rb', line 18

def parse_nutrition
  recipe.nutrition.tap do |nutrition|
    nutrition[:calories] = nutrition_property_value(:calories)
    nutrition[:cholesterol] = nutrition_property_value(:cholesterolcontent)
    nutrition[:fiber] = nutrition_property_value(:fibercontent)
    nutrition[:protein] = nutrition_property_value(:proteincontent)
    nutrition[:saturated_fat] = nutrition_property_value(:saturatedfatcontent)
    nutrition[:sodium] = nutrition_property_value(:sodiumcontent)
    nutrition[:sugar] = nutrition_property_value(:sugarcontent)
    nutrition[:total_carbohydrates] = nutrition_property_value(:carbohydratecontent)
    nutrition[:total_fat] = nutrition_property_value(:fatcontent)
    nutrition[:trans_fat] = nutrition_property_value(:transfatcontent)
    nutrition[:unsaturated_fat] = nutrition_property_value(:unsaturatedfatcontent)
  end
end

#parse_yieldObject



34
35
36
# File 'lib/hangry/parsers/non_standard/eating_well_parser.rb', line 34

def parse_yield
  value(node_with_itemprop(:recipeyield).content) || NullObject.new
end