Skip to content

Commit

Permalink
Simplify SchemaOrgRecipeParser#parse_instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
skalee authored and lukeasrodgers committed Jan 18, 2017
1 parent 3110cda commit 6cf74de
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/hangry/schema_org_recipe_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,18 @@ def parse_image_url
value(node['src']) || value(node['content'])
end
def parse_ingredients
nodes_with_itemprop(self.class.ingredient_itemprop).map(&:content).map { |ingredient|
# remove newlines and excess whitespace from ingredients
ingredient
nodes_with_itemprop(self.class.ingredient_itemprop).map { |node|
node.content.strip
}.reject(&:blank?)
end
def parse_instructions
# => NOT THIS:
#nodes_with_itemprop(:recipeInstructions).map(&:content).join("\n")
inst = ""
# Some sites like may have their recipe instructions doubled if they
# support different ways of presentation.
# E.g. http://www.pillsbury.com/recipes/big-cheesy-pepperoni-pockets/a17766e6-30ce-4a0c-af08-72533bb9b449
# has its steps doubled ("step by step" and "list" modes).
nodes_with_itemprop(:recipeInstructions).map { |i|
inst += i.content.strip + "\n" unless inst.include?(i.content.strip)
}
inst
i.content.strip
}.uniq.join("\n")
end
def parse_name
node_with_itemprop(:name).content
Expand Down

0 comments on commit 6cf74de

Please sign in to comment.