Class: LoveOfTea::Tea
- Inherits:
-
Object
- Object
- LoveOfTea::Tea
- Defined in:
- lib/love_of_tea/tea.rb
Constant Summary collapse
- @@all =
[]
- @@cart =
[]
Instance Attribute Summary collapse
-
#caffeine ⇒ Object
Returns the value of attribute caffeine.
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
Returns the value of attribute name.
-
#price ⇒ Object
Returns the value of attribute price.
-
#type ⇒ Object
Returns the value of attribute type.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .all ⇒ Object
- .black ⇒ Object
- .cart ⇒ Object
- .chai ⇒ Object
- .clear_all ⇒ Object
- .create_from_collection(tea_url) ⇒ Object
- .green ⇒ Object
- .herbal ⇒ Object
- .price_by_name(teaname) ⇒ Object
- .white ⇒ Object
Instance Method Summary collapse
-
#initialize(teahash) ⇒ Tea
constructor
A new instance of Tea.
- #save ⇒ Object
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
#caffeine ⇒ Object
Returns the value of attribute caffeine.
6 7 8 |
# File 'lib/love_of_tea/tea.rb', line 6 def caffeine @caffeine end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/love_of_tea/tea.rb', line 6 def description @description end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/love_of_tea/tea.rb', line 6 def name @name end |
#price ⇒ Object
Returns the value of attribute price.
6 7 8 |
# File 'lib/love_of_tea/tea.rb', line 6 def price @price end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/love_of_tea/tea.rb', line 6 def type @type end |
#url ⇒ Object
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
.all ⇒ Object
21 22 23 |
# File 'lib/love_of_tea/tea.rb', line 21 def self.all @@all end |
.black ⇒ Object
43 44 45 |
# File 'lib/love_of_tea/tea.rb', line 43 def self.black @@all.reject {|tea| tea.type != "Black"} end |
.cart ⇒ Object
64 65 66 |
# File 'lib/love_of_tea/tea.rb', line 64 def self.cart @@cart end |
.chai ⇒ Object
51 52 53 |
# File 'lib/love_of_tea/tea.rb', line 51 def self.chai @@all.reject {|tea| tea.type != "Chai"} end |
.clear_all ⇒ Object
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 |
.green ⇒ Object
35 36 37 |
# File 'lib/love_of_tea/tea.rb', line 35 def self.green @@all.reject {|tea| tea.type != "Green"} end |
.herbal ⇒ Object
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 |
.white ⇒ Object
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
#save ⇒ Object
60 61 62 |
# File 'lib/love_of_tea/tea.rb', line 60 def save @@cart << self end |