Class: Drink

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

Constant Summary collapse

@@all =
[]
@@milk =
[]
@@no_milk =
[]
@@all_sorted =
[]
@@milk_sorted =
[]
@@no_milk_sorted =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, milk = "", description, ratio, cup) ⇒ Drink

Returns a new instance of Drink.



12
13
14
15
16
17
18
19
20
21
# File 'lib/coffee_drinks/drink.rb', line 12

def initialize (name, milk = "", description, ratio, cup)
    @name = name
    @milk = milk
    @description = description
    @ratio = ratio
    @cup = cup
    @@all << self
    @@milk << self if milk == "yes"
    @@no_milk << self if milk == "no"
end

Instance Attribute Details

#cupObject

Returns the value of attribute cup.



10
11
12
# File 'lib/coffee_drinks/drink.rb', line 10

def cup
  @cup
end

#descriptionObject

Returns the value of attribute description.



10
11
12
# File 'lib/coffee_drinks/drink.rb', line 10

def description
  @description
end

#milkObject

Returns the value of attribute milk.



10
11
12
# File 'lib/coffee_drinks/drink.rb', line 10

def milk
  @milk
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/coffee_drinks/drink.rb', line 10

def name
  @name
end

#ratioObject

Returns the value of attribute ratio.



10
11
12
# File 'lib/coffee_drinks/drink.rb', line 10

def ratio
  @ratio
end

Class Method Details

.allObject



24
25
26
# File 'lib/coffee_drinks/drink.rb', line 24

def self.all
    @@all
end

.milkObject



28
29
30
# File 'lib/coffee_drinks/drink.rb', line 28

def self.milk
    @@milk
end

.no_milkObject



32
33
34
# File 'lib/coffee_drinks/drink.rb', line 32

def self.no_milk
    @@no_milk
end

.sorted_allObject



36
37
38
39
# File 'lib/coffee_drinks/drink.rb', line 36

def self.sorted_all
    self.all.sort_by {|drink| drink.name}.each {|instance| @@all_sorted << instance }
    @@all_sorted
end

.sorted_milkObject



41
42
43
44
# File 'lib/coffee_drinks/drink.rb', line 41

def self.sorted_milk
    self.milk.sort_by {|drink| drink.name}.each {|instance| @@milk_sorted << instance }
    @@milk_sorted
end

.sorted_no_milkObject



47
48
49
50
# File 'lib/coffee_drinks/drink.rb', line 47

def self.sorted_no_milk
    self.no_milk.sort_by {|drink| drink.name}.each {|instance| @@no_milk_sorted << instance }
    @@no_milk_sorted
end