Class: Frodo::Properties::Decimal

Inherits:
Frodo::Property show all
Defined in:
lib/frodo/properties/decimal.rb

Overview

Defines the Decimal Frodo type.

Instance Attribute Summary

Attributes inherited from Frodo::Property

#name, #options

Instance Method Summary collapse

Methods inherited from Frodo::Property

#==, #allows_nil?, #concurrency_mode, from_xml, #initialize, #json_value, #strict?, #to_xml, #xml_value

Constructor Details

This class inherits a constructor from Frodo::Property

Instance Method Details

#typeObject

The Frodo type name



27
28
29
# File 'lib/frodo/properties/decimal.rb', line 27

def type
  'Edm.Decimal'
end

#url_valueString

Value to be used in URLs.

Returns:



33
34
35
# File 'lib/frodo/properties/decimal.rb', line 33

def url_value
  "#{value.to_f}"
end

#valueBigDecimal?

Returns the property value, properly typecast

Returns:

  • (BigDecimal, nil)


7
8
9
10
11
12
13
# File 'lib/frodo/properties/decimal.rb', line 7

def value
  if (@value.nil? || @value.empty?) && (!strict? && allows_nil?)
    nil
  else
    BigDecimal(@value)
  end
end

#value=(new_value) ⇒ Object

Sets the property value



17
18
19
20
21
22
23
24
# File 'lib/frodo/properties/decimal.rb', line 17

def value=(new_value)
  @value = if (new_value.nil? && !strict? && allows_nil?)
              nil
            else
              validate(BigDecimal(new_value.to_s))
              new_value.to_s
            end
end