Class: Quantified::Coder
- Inherits:
-
Object
- Object
- Quantified::Coder
- Defined in:
- lib/quantified/coder.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Instance Method Summary collapse
- #dump(quantity) ⇒ Object
-
#initialize(attribute, unit) ⇒ Coder
constructor
A new instance of Coder.
- #load(amount) ⇒ Object
Constructor Details
#initialize(attribute, unit) ⇒ Coder
Returns a new instance of Coder.
5 6 7 8 |
# File 'lib/quantified/coder.rb', line 5 def initialize(attribute, unit) @attribute = attribute @unit = unit end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
3 4 5 |
# File 'lib/quantified/coder.rb', line 3 def attribute @attribute end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
3 4 5 |
# File 'lib/quantified/coder.rb', line 3 def unit @unit end |
Instance Method Details
#dump(quantity) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/quantified/coder.rb', line 14 def dump(quantity) conversion = "to_#{unit}" if quantity.respond_to?(conversion) quantity.send(conversion) else quantity end end |
#load(amount) ⇒ Object
10 11 12 |
# File 'lib/quantified/coder.rb', line 10 def load(amount) attribute.new(amount, unit) unless amount.nil? end |