Class: RecipeCrawler::Recipe

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Recipe

Instanciate a Recipe object with data crawled from an url

Parameters:

  • url (String)

    representing an url from Marmiton or 750g website



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

#cooktimeObject (readonly)

Returns the value of attribute cooktime.



14
15
16
# File 'lib/recipe_crawler.rb', line 14

def cooktime
  @cooktime
end

#imageObject (readonly)

Returns the value of attribute image.



14
15
16
# File 'lib/recipe_crawler.rb', line 14

def image
  @image
end

#ingredientsObject (readonly)

Returns the value of attribute ingredients.



14
15
16
# File 'lib/recipe_crawler.rb', line 14

def ingredients
  @ingredients
end

#preptimeObject (readonly)

Returns the value of attribute preptime.



14
15
16
# File 'lib/recipe_crawler.rb', line 14

def preptime
  @preptime
end

#stepsObject (readonly)

Returns the value of attribute steps.



14
15
16
# File 'lib/recipe_crawler.rb', line 14

def steps
  @steps
end

#titleObject (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_hashHash

export object properties to hash

Returns:

  • (Hash)

    as object’s properties



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_jsonString

convert object properties to json

Returns:

  • (String)

    data formated in JSON



51
52
53
# File 'lib/recipe_crawler.rb', line 51

def to_json
  return self.to_hash.to_json
end