Module: UnitedAttributes::Model
- Defined in:
- lib/united_attributes/model.rb
Instance Method Summary collapse
-
#unite(accessor, unit, options = {}) ⇒ Object
Should be called like: unite :attribute, :unit, options e.g.
Instance Method Details
#unite(accessor, unit, options = {}) ⇒ Object
Should be called like: unite :attribute, :unit, options e.g. unite :duration, :minute, domain: :time, precision: 2,
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/united_attributes/model.rb', line 9 def unite(accessor, unit, = {}) .reverse_merge!({precision: 0}) [:unit] = unit unless .has_key?(:domain) UnitedAttributes::DOMAINS.each do |key, value| if value.has_key? unit [:domain] = key break end end end class_eval do define_method "united_#{accessor}" do Attribute.new(self.send(accessor), ) end end end |