Class: Tychus::Parsers::KraftRecipesParser

Inherits:
SchemaOrgParser show all
Defined in:
lib/tychus/parsers/kraft_recipes_parser.rb

Instance Attribute Summary

Attributes inherited from Base

#doc, #recipe, #recipe_doc, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SchemaOrgParser

#initialize, #itemprop_node_for, review_doc, root_doc, #strip_review_microformat, #strip_video_object_microformat, video_object_doc

Methods inherited from Base

#Value, #clean_instructions, #initialize, #parse, #parse_author, #parse_cook_time, #parse_duration, #parse_image, #parse_prep_time, #parse_recipe_yield, #parse_total_time, recipe_attributes, #recipe_attributes

Constructor Details

This class inherits a constructor from Tychus::Parsers::SchemaOrgParser

Class Method Details

.uri_hostObject



6
7
8
# File 'lib/tychus/parsers/kraft_recipes_parser.rb', line 6

def self.uri_host
  "kraftrecipes.com"
end

Instance Method Details

#parse_descriptionObject



10
11
12
13
14
# File 'lib/tychus/parsers/kraft_recipes_parser.rb', line 10

def parse_description
  # description can be found in .recipeDesc or meta tag in header
  # TODO: pull out meta tag parsing into own methods/class?
  doc.css('meta[name="description"]').first.attr('content')
end

#parse_ingredientsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tychus/parsers/kraft_recipes_parser.rb', line 34

def parse_ingredients
  # NOT FIRST
  # "1 lb.\r\n\t\t\t\t\t\t\t\t boneless skinless chicken breasts, cut into 1-1/2-inch pieces", "2 cups\r\n\t\t\t\t\t\t\t\t fresh pineapple chunks (1-1/2 inch)", "1 \r\n\t\t\t\t\t\t\t\t each red and green pepper, cut into 1-1/2-inch pieces", "1/2 cup\r\n\t\t\t\t\t\t\t\t KRAFT Original Barbecue Sauce", "3 Tbsp.\r\n\t\t\t\t\t\t\t\t frozen orange juice concentrate, thawed"
  recipe_doc
    .css('[itemprop="ingredients"]')
    .map do|ingredient_node|
      ingredient_node
        .element_children
        .map do |node| node.content
          .lstrip
          .rstrip
          .squeeze(" ")
          .gsub(/(\r|\n|\t)/,'')
        end.join(" ")
    end.reject(&:blank?)
end

#parse_nameObject



16
17
18
19
20
# File 'lib/tychus/parsers/kraft_recipes_parser.rb', line 16

def parse_name
  # "\r\n\tSweet BBQ Chicken Kabobs\r\n\t"
  result = super
  result.gsub(/(\r|\n|\t)/,'')
end

#parse_recipe_instructionsObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/tychus/parsers/kraft_recipes_parser.rb', line 22

def parse_recipe_instructions
  itemprop_node_for(:recipeInstructions)
    .element_children
    .map do|x|
      x.content
        .squeeze(" ")
        .rstrip
        .split("\r\n\t")
        .map{|x|x.gsub(/\t/,'')}
    end.flatten.reject(&:blank?)
end