Class: Beerxml::Properties::Property

Inherits:
DataMapper::Property::Float
  • Object
show all
Defined in:
lib/beerxml/properties.rb

Direct Known Subclasses

Temperature, Time, Volume, Weight

Instance Method Summary collapse

Instance Method Details

#custom?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/beerxml/properties.rb', line 7

def custom?
  true
end

#dump(value) ⇒ Object



25
26
27
28
# File 'lib/beerxml/properties.rb', line 25

def dump(value)
  return if value.nil?
  value.in(base_unit).to_f
end

#load(value) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/beerxml/properties.rb', line 15

def load(value)
  return if value.nil?
  if value.is_a?(Beerxml::Unit)
    raise(ArgumentError, "#{value.inspect} is not a #{unit_type}") unless value.type == unit_type
    value
  else
    U(value, base_unit)
  end
end

#primitive?(value) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/beerxml/properties.rb', line 11

def primitive?(value)
  value.is_a?(Beerxml::Unit) && value.type == unit_type
end

#typecast_to_primitive(value) ⇒ Object



30
31
32
# File 'lib/beerxml/properties.rb', line 30

def typecast_to_primitive(value)
  load(value)
end