Class: LoveOfTea::Tea

Inherits:
Object
  • Object
show all
Defined in:
lib/love_of_tea/tea.rb

Constant Summary collapse

@@all =
[]
@@cart =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(teahash) ⇒ Tea

Returns a new instance of Tea.



11
12
13
14
15
16
17
18
19
# File 'lib/love_of_tea/tea.rb', line 11

def initialize(teahash)
  @name = teahash[:name]
  @type = teahash[:type]
  @price = teahash[:price] ? teahash[:price] : teahash[:price2]
  @description = teahash[:description]
  @caffeine = if teahash[:type] == "Green" then "medium" elsif teahash[:type] == "White" then "low" elsif teahash[:type] == "Black" || teahash[:type] == "Chai"  then "high" else nil end
  @url = teahash[:url]
  @@all << self
end

Instance Attribute Details

#caffeineObject

Returns the value of attribute caffeine.



6
7
8
# File 'lib/love_of_tea/tea.rb', line 6

def caffeine
  @caffeine
end

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/love_of_tea/tea.rb', line 6

def description
  @description
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/love_of_tea/tea.rb', line 6

def name
  @name
end

#priceObject

Returns the value of attribute price.



6
7
8
# File 'lib/love_of_tea/tea.rb', line 6

def price
  @price
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/love_of_tea/tea.rb', line 6

def type
  @type
end

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/love_of_tea/tea.rb', line 6

def url
  @url
end

Class Method Details

.allObject



21
22
23
# File 'lib/love_of_tea/tea.rb', line 21

def self.all
  @@all
end

.blackObject



43
44
45
# File 'lib/love_of_tea/tea.rb', line 43

def self.black
  @@all.reject {|tea| tea.type != "Black"}
end

.cartObject



64
65
66
# File 'lib/love_of_tea/tea.rb', line 64

def self.cart
  @@cart
end

.chaiObject



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

def self.chai
  @@all.reject {|tea| tea.type != "Chai"}
end

.clear_allObject



25
26
27
# File 'lib/love_of_tea/tea.rb', line 25

def self.clear_all
  @@all.clear
end

.create_from_collection(tea_url) ⇒ Object



29
30
31
32
33
# File 'lib/love_of_tea/tea.rb', line 29

def self.create_from_collection(tea_url)
  LoveOfTea::Scraper.scrape_by_tea_url(tea_url).each do |teahash|
  self.new(teahash)
  end
end

.greenObject



35
36
37
# File 'lib/love_of_tea/tea.rb', line 35

def self.green
  @@all.reject {|tea| tea.type != "Green"}
end

.herbalObject



47
48
49
# File 'lib/love_of_tea/tea.rb', line 47

def self.herbal
  @@all.reject {|tea| tea.type != "Herbal"}
end

.price_by_name(teaname) ⇒ Object



55
56
57
58
# File 'lib/love_of_tea/tea.rb', line 55

def self.price_by_name(teaname)
  tea = @@all.detect {|tea| tea.name == teaname}
  tea.price
end

.whiteObject



39
40
41
# File 'lib/love_of_tea/tea.rb', line 39

def self.white
  @@all.reject {|tea| tea.type != "White"}
end

Instance Method Details

#saveObject



60
61
62
# File 'lib/love_of_tea/tea.rb', line 60

def save
  @@cart << self
end