Class: RecipeScraper::Recipe
- Inherits:
-
Object
- Object
- RecipeScraper::Recipe
- Defined in:
- lib/recipe_scraper.rb
Overview
represent a recipe fetched from an Url
Constant Summary collapse
- MARMITON_HOST =
{ desktop: 'marmiton.org/', mobile: 'm.marmiton.org/' }.freeze
- G750_HOST =
{ desktop: '750g.com' }.freeze
- CUISINEAZ_HOST =
{ desktop: 'cuisineaz.com/' }.freeze
Instance Attribute Summary collapse
-
#cooktime ⇒ Object
readonly
Returns the value of attribute cooktime.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#ingredients ⇒ Object
readonly
Returns the value of attribute ingredients.
-
#nb_of_persons ⇒ Object
readonly
Returns the value of attribute nb_of_persons.
-
#preptime ⇒ Object
readonly
Returns the value of attribute preptime.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(url) ⇒ Recipe
constructor
Instanciate a Recipe object with data crawled from an url.
-
#to_hash ⇒ Hash
export object properties to hash.
-
#to_json ⇒ String
convert object properties to json.
Constructor Details
#initialize(url) ⇒ Recipe
Instanciate a Recipe object with data crawled from an url
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/recipe_scraper.rb', line 19 def initialize(url) if marmiton_host? url fetch_from_marmiton url elsif g750_host? url fetch_from_g750 url elsif cuisineaz_host? url fetch_from_cuisineaz url else raise ArgumentError, 'Instantiation cancelled (Host not supported).' end end |
Instance Attribute Details
#cooktime ⇒ Object (readonly)
Returns the value of attribute cooktime.
10 11 12 |
# File 'lib/recipe_scraper.rb', line 10 def cooktime @cooktime end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
10 11 12 |
# File 'lib/recipe_scraper.rb', line 10 def image @image end |
#ingredients ⇒ Object (readonly)
Returns the value of attribute ingredients.
10 11 12 |
# File 'lib/recipe_scraper.rb', line 10 def ingredients @ingredients end |
#nb_of_persons ⇒ Object (readonly)
Returns the value of attribute nb_of_persons.
10 11 12 |
# File 'lib/recipe_scraper.rb', line 10 def nb_of_persons @nb_of_persons end |
#preptime ⇒ Object (readonly)
Returns the value of attribute preptime.
10 11 12 |
# File 'lib/recipe_scraper.rb', line 10 def preptime @preptime end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
10 11 12 |
# File 'lib/recipe_scraper.rb', line 10 def steps @steps end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
10 11 12 |
# File 'lib/recipe_scraper.rb', line 10 def title @title end |
Instance Method Details
#to_hash ⇒ Hash
export object properties to hash
37 38 39 40 41 42 43 44 |
# File 'lib/recipe_scraper.rb', line 37 def to_hash attrs = {} instance_variables.each do |var| str = var.to_s.gsub /^@/, '' attrs[str.to_sym] = instance_variable_get(var) end attrs end |
#to_json ⇒ String
convert object properties to json
49 50 51 |
# File 'lib/recipe_scraper.rb', line 49 def to_json to_hash.to_json end |