Class: Strain

Inherits:
Object
  • Object
show all
Defined in:
lib/rolling_paper/strain.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Strain

Returns a new instance of Strain.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rolling_paper/strain.rb', line 36

def initialize(data)
  @key = data["Key"]
  @id = data["Id"]
  @name = data["Name"]
  @category = data["Category"]
  @description = data["Abstract"]
  @symbol = data["Symbol"]
  @overview = data["Overview"]
  @url = data["Url"]
  @rating = data["Rating"]
  @effects = data["Effects"] #returns an array of hashes for each effect
  @medical_uses = data["Medical"]
  @side_effects = data["Negative"]
  @reviews = data["Reviews"]
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def category
  @category
end

#descriptionObject (readonly)

Returns the value of attribute description.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def description
  @description
end

#effectsObject (readonly)

Returns the value of attribute effects.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def effects
  @effects
end

#idObject (readonly)

Returns the value of attribute id.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def key
  @key
end

#medical_usesObject (readonly)

Returns the value of attribute medical_uses.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def medical_uses
  @medical_uses
end

#nameObject (readonly)

Returns the value of attribute name.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def name
  @name
end

#overviewObject (readonly)

Returns the value of attribute overview.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def overview
  @overview
end

#ratingObject (readonly)

Returns the value of attribute rating.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def rating
  @rating
end

#reviewsObject (readonly)

Returns the value of attribute reviews.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def reviews
  @reviews
end

#side_effectsObject (readonly)

Returns the value of attribute side_effects.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def side_effects
  @side_effects
end

#symbolObject (readonly)

Returns the value of attribute symbol.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def symbol
  @symbol
end

#urlObject (readonly)

Returns the value of attribute url.



32
33
34
# File 'lib/rolling_paper/strain.rb', line 32

def url
  @url
end

Class Method Details

.all_key_namesObject



12
13
14
15
16
17
18
# File 'lib/rolling_paper/strain.rb', line 12

def self.all_key_names
  response = Faraday.get("http://www.leafly.com/api/strains")
  strains_json = JSON.parse(response.body)
  strains_json.collect do |strain|
    strain["Key"]
  end
end

.all_strainsObject



6
7
8
9
10
# File 'lib/rolling_paper/strain.rb', line 6

def self.all_strains 
  response = Faraday.get("http://www.leafly.com/api/strains")
  strains_json = JSON.parse(response.body)
  strains_json.collect {|strain| new (strain)}
end

.find_by_category(category) ⇒ Object



26
27
28
29
30
# File 'lib/rolling_paper/strain.rb', line 26

def self.find_by_category(category)
  response = Faraday.get("http://www.leafly.com/api/strains?category=#{category}")
  strains_json = JSON.parse(response.body)
  strains_json.collect {|strain| new (strain)}
end

.find_by_key(key) ⇒ Object



20
21
22
23
24
# File 'lib/rolling_paper/strain.rb', line 20

def self.find_by_key(key)
  response = Faraday.get("http://www.leafly.com/api/details/#{key}")
  strain_json = JSON.parse(response.body)
  new (strain_json)
end