Class: PageParser
- Inherits:
-
Object
- Object
- PageParser
- Defined in:
- lib/allrecipes/page_parser.rb
Instance Method Summary collapse
- #filtered_recipes ⇒ Object
- #get_recipes ⇒ Object
-
#initialize(page, options = {}) ⇒ PageParser
constructor
A new instance of PageParser.
- #recipe_info ⇒ Object
- #recipe_info_class ⇒ Object
- #recipe_link(info) ⇒ Object
- #recipes ⇒ Object
- #recipes_grid ⇒ Object
- #recipes_grid_class ⇒ Object
- #title_class ⇒ Object
Constructor Details
#initialize(page, options = {}) ⇒ PageParser
Returns a new instance of PageParser.
3 4 5 6 7 8 9 |
# File 'lib/allrecipes/page_parser.rb', line 3 def initialize(page, ={}) @page = page @recipes = [] @options = @limit = [:limit] get_recipes end |
Instance Method Details
#filtered_recipes ⇒ Object
27 28 29 |
# File 'lib/allrecipes/page_parser.rb', line 27 def filtered_recipes @limit ? recipe_info.take(@limit) : recipe_info end |
#get_recipes ⇒ Object
43 44 45 46 47 48 |
# File 'lib/allrecipes/page_parser.rb', line 43 def get_recipes filtered_recipes.each do |info| recipe_link = recipe_link(info) @recipes << RecipeParser.new(recipe_link, @options[:keys]).recipe end end |
#recipe_info ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/allrecipes/page_parser.rb', line 19 def recipe_info if @options[:type] == "ingredient" @page.search(recipe_info_class) else recipes_grid.search(recipe_info_class) end end |
#recipe_info_class ⇒ Object
11 12 13 |
# File 'lib/allrecipes/page_parser.rb', line 11 def recipe_info_class ".recipe-info" end |
#recipe_link(info) ⇒ Object
39 40 41 |
# File 'lib/allrecipes/page_parser.rb', line 39 def recipe_link(info) "http://allrecipes.com" + info.search(title_class)[0].attributes["href"].value end |
#recipes ⇒ Object
50 51 52 |
# File 'lib/allrecipes/page_parser.rb', line 50 def recipes @recipes end |
#recipes_grid ⇒ Object
35 36 37 |
# File 'lib/allrecipes/page_parser.rb', line 35 def recipes_grid @page.search(recipes_grid_class)[-1] end |
#recipes_grid_class ⇒ Object
31 32 33 |
# File 'lib/allrecipes/page_parser.rb', line 31 def recipes_grid_class ".grid-view" end |
#title_class ⇒ Object
15 16 17 |
# File 'lib/allrecipes/page_parser.rb', line 15 def title_class ".title" end |