Class: RecipeCrawler::Recipe
- Inherits:
-
Object
- Object
- RecipeCrawler::Recipe
- Defined in:
- lib/recipe_crawler.rb
Overview
represent a recipe fetched from an Url
Constant Summary collapse
- MARMITON_HOST =
{desktop: 'http://www.marmiton.org/', mobile: 'http://m.marmiton.org/'}
- G750_HOST =
'http://www.750g.com'
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.
-
#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
24 25 26 27 28 29 30 31 32 |
# File 'lib/recipe_crawler.rb', line 24 def initialize url if marmiton_host? url fetch_from_marmiton url elsif g750_host? url fetch_from_g750 url else raise ArgumentError, "Instantiation cancelled (Host not supported)." end end |
Instance Attribute Details
#cooktime ⇒ Object (readonly)
Returns the value of attribute cooktime.
14 15 16 |
# File 'lib/recipe_crawler.rb', line 14 def cooktime @cooktime end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
14 15 16 |
# File 'lib/recipe_crawler.rb', line 14 def image @image end |
#ingredients ⇒ Object (readonly)
Returns the value of attribute ingredients.
14 15 16 |
# File 'lib/recipe_crawler.rb', line 14 def ingredients @ingredients end |
#preptime ⇒ Object (readonly)
Returns the value of attribute preptime.
14 15 16 |
# File 'lib/recipe_crawler.rb', line 14 def preptime @preptime end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
14 15 16 |
# File 'lib/recipe_crawler.rb', line 14 def steps @steps end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
14 15 16 |
# File 'lib/recipe_crawler.rb', line 14 def title @title end |
Instance Method Details
#to_hash ⇒ Hash
export object properties to hash
38 39 40 41 42 43 44 45 |
# File 'lib/recipe_crawler.rb', line 38 def to_hash attrs = Hash.new 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
51 52 53 |
# File 'lib/recipe_crawler.rb', line 51 def to_json return self.to_hash.to_json end |