Class: Brewser::Model::Units::Units
- Inherits:
-
DataMapper::Property::String
- Object
- DataMapper::Property::String
- Brewser::Model::Units::Units
show all
- Defined in:
- lib/brewser/model/units.rb
Instance Method Summary
collapse
Instance Method Details
#custom? ⇒ Boolean
Declare this property as custom
8
9
10
|
# File 'lib/brewser/model/units.rb', line 8
def custom?
true
end
|
#dump(value) ⇒ Object
35
36
37
38
|
# File 'lib/brewser/model/units.rb', line 35
def dump(value)
return if value.nil?
value.u.to_s
end
|
#load(value) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/brewser/model/units.rb', line 25
def load(value)
return if value.nil?
if !value.u.unitless?
raise(ArgumentError, "#{value.inspect} is not a #{kind_of}") unless kind_of.nil? or value.u.kind == kind_of
value.u
else
"#{value} #{base_unit}".u
end
end
|
#primitive?(value) ⇒ Boolean
21
22
23
|
# File 'lib/brewser/model/units.rb', line 21
def primitive?(value)
value.is_a?(Unit) && valid_kind?(value)
end
|
#typecast_to_primitive(value) ⇒ Object
40
41
42
|
# File 'lib/brewser/model/units.rb', line 40
def typecast_to_primitive(value)
load(value)
end
|
#valid_kind?(value) ⇒ Boolean
Compare the values kind (mass, volume, etc) to the object classes kind_of
16
17
18
|
# File 'lib/brewser/model/units.rb', line 16
def valid_kind?(value)
value.kind == kind_of
end
|