lib/serious-eats/scraper.rb in serious-eats-0.1.1 vs lib/serious-eats/scraper.rb in serious-eats-0.1.2

- old
+ new

@@ -23,35 +23,35 @@ recipe end end def fetch_recipe_data(recipe) - get_recipe_data(recipe).map do |block| - recipe.description = block.css(".recipe-introduction-body p:not(.caption)").map do |description| - description.text.strip - end.select do |description| - # some recipes have some empty <p> tags that need to be filtered out - description.length > 0 - end + block = get_recipe_data(recipe) - recipe.portion = block.css("span.info.yield").text.strip - recipe.active_time = block.css("ul.recipe-about li:nth-child(2) span.info").text.strip - recipe.total_time = block.css("ul.recipe-about li:nth-child(3) span.info").text.strip - recipe.rating = block.css("span.info.rating-value").text.strip.to_f.round(1) + recipe.description = block.css(".recipe-introduction-body p:not(.caption)").map do |description| + description.text.strip + end.select do |description| + # some recipes have some empty <p> tags that need to be filtered out + description.length > 0 + end - recipe.ingredients = block.css("li.ingredient").map do |ingredient| - text = ingredient.text.strip + recipe.portion = block.css("span.info.yield").text.strip + recipe.active_time = block.css("ul.recipe-about li:nth-child(2) span.info").text.strip + recipe.total_time = block.css("ul.recipe-about li:nth-child(3) span.info").text.strip + recipe.rating = block.css("span.info.rating-value").text.strip.to_f.round(1) - if ingredient.css("strong").any? - text = "\n#{text.underline}" - end + recipe.ingredients = block.css("li.ingredient").map do |ingredient| + text = ingredient.text.strip - text + if ingredient.css("strong").any? + text = "\n#{text.underline}" end - recipe.directions = block.css(".recipe-procedure-text").map do |direction| - direction.text.strip - end + text + end + + recipe.directions = block.css(".recipe-procedure-text").map do |direction| + direction.text.strip end end end end \ No newline at end of file