Class: Tea

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Tea

Returns a new instance of Tea.



9
10
11
12
13
14
15
# File 'lib/tea.rb', line 9

def initialize(name)
    @name = name
    @@all << self 
    self.description = ""
    self.ingredients = "" 
    self.pricing = {} 
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



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

def category
  @category
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#ingredientsObject

Returns the value of attribute ingredients.



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

def ingredients
  @ingredients
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#pricingObject

Returns the value of attribute pricing.



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

def pricing
  @pricing
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



17
18
19
# File 'lib/tea.rb', line 17

def self.all 
    @@all
end

.all_teas_in(tea_category) ⇒ Object



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

def self.all_teas_in(tea_category)
    @@all.select {|tea| tea.category.name == tea_category}
end

.find_by_ingredient(ingredient) ⇒ Object



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

def self.find_by_ingredient(ingredient)
    @@all.select { |tea| tea.ingredients.include?(ingredient) } 
end

.find_by_name(name) ⇒ Object



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

def self.find_by_name(name)
    @@all.detect {|tea| tea.name == name}
end

.get_random_teaObject



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

def self.get_random_tea
    rand_tea  = Tea.all.sample 
    rand_tea.name 
end

Instance Method Details

#check_for_tea_infoObject

checks whether or not we’ve already scraped the info about this particular tea object returns true if tea info has already been acquired



27
28
29
# File 'lib/tea.rb', line 27

def check_for_tea_info
    self.ingredients.length > 0 && self.description.length > 0 && self.pricing.length > 0 
end