Class: Pueri::DoseCalc
- Inherits:
-
Object
- Object
- Pueri::DoseCalc
- Defined in:
- lib/pueri/dosecalc.rb
Overview
Calculates the prescription of a given medication given the weight of the pacient, the dose-per-weight-day, the concentration of the medication's presentation and the periodicity of takes in hours.
Instance Attribute Summary collapse
-
#conc_unit ⇒ Object
Returns the value of attribute conc_unit.
-
#concentration ⇒ Object
readonly
Returns the value of attribute concentration.
-
#days ⇒ Object
readonly
Returns the value of attribute days.
-
#dose ⇒ Object
readonly
Returns the value of attribute dose.
-
#dose_unit ⇒ Object
Returns the value of attribute dose_unit.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
-
#initialize(params) ⇒ DoseCalc
constructor
Calculate the dosage for each taking of a given medicine.
-
#to_f ⇒ Float
Outputs the calculated dosage for each taking.
-
#to_s(pretty = false) ⇒ String
Outputs the calculated dosage into a prescription string.
Constructor Details
#initialize(params) ⇒ DoseCalc
Calculate the dosage for each taking of a given medicine.
23 24 25 26 |
# File 'lib/pueri/dosecalc.rb', line 23 def initialize(params) init_vars(params) @result = ((@weight * @dose * @time) / (24.0 * @concentration)).round(3) end |
Instance Attribute Details
#conc_unit ⇒ Object
Returns the value of attribute conc_unit
9 10 11 |
# File 'lib/pueri/dosecalc.rb', line 9 def conc_unit @conc_unit end |
#concentration ⇒ Object (readonly)
Returns the value of attribute concentration
8 9 10 |
# File 'lib/pueri/dosecalc.rb', line 8 def concentration @concentration end |
#days ⇒ Object (readonly)
Returns the value of attribute days
8 9 10 |
# File 'lib/pueri/dosecalc.rb', line 8 def days @days end |
#dose ⇒ Object (readonly)
Returns the value of attribute dose
8 9 10 |
# File 'lib/pueri/dosecalc.rb', line 8 def dose @dose end |
#dose_unit ⇒ Object
Returns the value of attribute dose_unit
9 10 11 |
# File 'lib/pueri/dosecalc.rb', line 9 def dose_unit @dose_unit end |
#name ⇒ Object (readonly)
Returns the value of attribute name
8 9 10 |
# File 'lib/pueri/dosecalc.rb', line 8 def name @name end |
#result ⇒ Object (readonly)
Returns the value of attribute result
8 9 10 |
# File 'lib/pueri/dosecalc.rb', line 8 def result @result end |
#time ⇒ Object (readonly)
Returns the value of attribute time
8 9 10 |
# File 'lib/pueri/dosecalc.rb', line 8 def time @time end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight
8 9 10 |
# File 'lib/pueri/dosecalc.rb', line 8 def weight @weight end |
Instance Method Details
#to_f ⇒ Float
Outputs the calculated dosage for each taking. E.g.
3.7
, as in _use 3.7 units of medication each time_.
48 49 50 |
# File 'lib/pueri/dosecalc.rb', line 48 def to_f @result end |
#to_s(pretty = false) ⇒ String
Outputs the calculated dosage into a prescription string.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pueri/dosecalc.rb', line 32 def to_s(pretty = false) if pretty pretty_to_s else [ '', "- #{@name} #{@concentration.to_i}#{@conc_unit.join '/'}", "Tomar #{@result}#{@conc_unit[1]} #{time_to_s} #{days_to_s}." ].join "\n" end end |