class Quantified::Coder

Attributes

attribute[R]
unit[R]

Public Class Methods

new(attribute, unit) click to toggle source
# File lib/quantified/coder.rb, line 5
def initialize(attribute, unit)
  @attribute = attribute
  @unit = unit
end

Public Instance Methods

dump(quantity) click to toggle source
# 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) click to toggle source
# File lib/quantified/coder.rb, line 10
def load(amount)
  attribute.new(amount, unit) unless amount.nil?
end