Class: Faded::Person
- Inherits:
-
Object
- Object
- Faded::Person
- Defined in:
- lib/faded/person.rb
Instance Attribute Summary collapse
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
-
#bac(time = nil) ⇒ Object
Blood Alcohol Concentration (by removing metabolized alcohol over drinking time.).
-
#bha ⇒ Object
Portion of body that holds alcohol.
- #drink(at = Time.now, what = :beer, how_many = 1) ⇒ Object
- #drinks ⇒ Object
- #hours_drinking ⇒ Object
-
#initialize(sex, weight, current_time = Time.now) ⇒ Person
constructor
A new instance of Person.
- #next_drink(drink) ⇒ Object
-
#shit_bac ⇒ Object
A less accurate way to measure.
- #total_alc_weight ⇒ Object
-
#wtac(alc_weight) ⇒ Object
Water Tissue Alcohol Concentration.
Constructor Details
#initialize(sex, weight, current_time = Time.now) ⇒ Person
Returns a new instance of Person.
5 6 7 8 9 10 11 |
# File 'lib/faded/person.rb', line 5 def initialize(sex, weight, current_time = Time.now) @sex = sex.to_s =~ /^(m|d)/i ? :male : :female @body_weight = weight @drinks = [] @time = current_time #- 90 @drank = 0 end |
Instance Attribute Details
#time ⇒ Object
Returns the value of attribute time.
3 4 5 |
# File 'lib/faded/person.rb', line 3 def time @time end |
Instance Method Details
#bac(time = nil) ⇒ Object
Blood Alcohol Concentration (by removing metabolized alcohol over drinking time.)
38 39 40 41 42 |
# File 'lib/faded/person.rb', line 38 def bac time = nil @time = parse_time(time) if time level = ("%.3f" % (wtac(total_alc_weight) - hours_drinking * WIDMARK_BETA)).to_f if drinks.size > 0 level && level > 0 ? level : 0.0 end |
#bha ⇒ Object
Portion of body that holds alcohol.
50 51 52 |
# File 'lib/faded/person.rb', line 50 def bha @body_weight * WIDMARK_R[@sex] end |
#drink(at = Time.now, what = :beer, how_many = 1) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/faded/person.rb', line 17 def drink at = Time.now, what = :beer, how_many = 1 how_many.times do |i| @drinks << Drink.new(what, parse_time(at)) end bac end |
#drinks ⇒ Object
24 25 26 |
# File 'lib/faded/person.rb', line 24 def drinks @drank == @drinks.size ? @drinks : @drinks.sort { |a,b| a.when <=> b.when }.reject { |d| d.when >= @time } end |
#hours_drinking ⇒ Object
28 29 30 |
# File 'lib/faded/person.rb', line 28 def hours_drinking (@time - drinks.first.when) / 3600 end |
#next_drink(drink) ⇒ Object
32 33 34 35 |
# File 'lib/faded/person.rb', line 32 def next_drink(drink) found = drinks[drinks.index(drink) + 1] found ? found.when : @time end |
#shit_bac ⇒ Object
A less accurate way to measure
56 57 58 59 60 61 62 |
# File 'lib/faded/person.rb', line 56 def shit_bac bac = drinks.inject(0.0) do |total, drink| concentration = wtac(drink.alcohol * ALC_WEIGHT) - drink.hours_ago(next_drink(drink)) * WIDMARK_BETA total += concentration < 0 ? 0 : concentration end ("%.3f" % bac).to_f end |
#total_alc_weight ⇒ Object
64 65 66 67 68 |
# File 'lib/faded/person.rb', line 64 def total_alc_weight drinks.inject(0) do |total, drink| total += drink.alcohol end * ALC_WEIGHT end |
#wtac(alc_weight) ⇒ Object
Water Tissue Alcohol Concentration
45 46 47 |
# File 'lib/faded/person.rb', line 45 def wtac alc_weight alc_weight * GRAVITY_OF_BLOOD / bha * 100 end |