Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor clean-ups in schema.org parser #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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