Class: Faded::Drink
- Inherits:
-
Object
- Object
- Faded::Drink
- Defined in:
- lib/faded/drink.rb
Constant Summary collapse
- @@drinks =
Amount of alchol in drinks by ounce
{ :manhattan => 1.15, :dry_martinni => 1.00, :malt_liqour => 0.71, :airline_miniature => 0.70, :whiskey_sour => 0.60, :wine => 0.55, :beer => 0.5, :near_beer => 0.28, }
Instance Attribute Summary collapse
-
#what ⇒ Object
Returns the value of attribute what.
-
#when ⇒ Object
Returns the value of attribute when.
Class Method Summary collapse
Instance Method Summary collapse
- #alcohol ⇒ Object
- #hours_ago(time = Time.now) ⇒ Object
-
#initialize(what, at = Time.now) ⇒ Drink
constructor
A new instance of Drink.
- #oz_to_lbs(oz) ⇒ Object
-
#percent_to_oz(percent, oz) ⇒ Object
For N fluid ounces of alcohol, find pure alcohol content from percentage.
-
#proof_to_percent(proof) ⇒ Object
Proof goes to 200.
- #to_s ⇒ Object
Constructor Details
#initialize(what, at = Time.now) ⇒ Drink
Returns a new instance of Drink.
17 18 19 20 21 |
# File 'lib/faded/drink.rb', line 17 def initialize what, at = Time.now @what = what.to_s.downcase.gsub(/\s/,'_').intern raise "Unknown drink" unless @@drinks.keys.include? @what @when = at end |
Instance Attribute Details
#what ⇒ Object
Returns the value of attribute what.
3 4 5 |
# File 'lib/faded/drink.rb', line 3 def what @what end |
#when ⇒ Object
Returns the value of attribute when.
3 4 5 |
# File 'lib/faded/drink.rb', line 3 def when @when end |
Class Method Details
.concoct(type, oz) ⇒ Object
35 36 37 |
# File 'lib/faded/drink.rb', line 35 def self.concoct type, oz @@drinks[type.to_s.downcase.gsub(/\s/,'_').intern] = oz end |
Instance Method Details
#alcohol ⇒ Object
31 32 33 |
# File 'lib/faded/drink.rb', line 31 def alcohol @@drinks[@what] end |
#hours_ago(time = Time.now) ⇒ Object
23 24 25 |
# File 'lib/faded/drink.rb', line 23 def hours_ago time = Time.now (time - @when) / 3600 end |
#oz_to_lbs(oz) ⇒ Object
50 51 52 |
# File 'lib/faded/drink.rb', line 50 def oz_to_lbs(oz) oz * ALC_WEIGHT end |
#percent_to_oz(percent, oz) ⇒ Object
For N fluid ounces of alcohol, find pure alcohol content from percentage.
46 47 48 |
# File 'lib/faded/drink.rb', line 46 def percent_to_oz(percent, oz) oz * percent end |
#proof_to_percent(proof) ⇒ Object
Proof goes to 200.
41 42 43 |
# File 'lib/faded/drink.rb', line 41 def proof_to_percent(proof) proof / 2 end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/faded/drink.rb', line 27 def to_s @when.strftime('%I:%M %a') end |