Class: Rfm::Result::Field
- Inherits:
-
Object
- Object
- Rfm::Result::Field
- Defined in:
- lib/rfm_result.rb
Instance Attribute Summary collapse
-
#global ⇒ Object
readonly
Returns the value of attribute global.
-
#max_repeats ⇒ Object
readonly
Returns the value of attribute max_repeats.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #coerce(value) ⇒ Object
-
#initialize(field) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(field) ⇒ Field
Returns a new instance of Field.
126 127 128 129 130 131 132 |
# File 'lib/rfm_result.rb', line 126 def initialize(field) @name = field.attributes['name'] @result = field.attributes['result'] @type = field.attributes['type'] @max_repeats = field.attributes['max-repeats'] @global = field.attributes['global'] end |
Instance Attribute Details
#global ⇒ Object (readonly)
Returns the value of attribute global.
134 135 136 |
# File 'lib/rfm_result.rb', line 134 def global @global end |
#max_repeats ⇒ Object (readonly)
Returns the value of attribute max_repeats.
134 135 136 |
# File 'lib/rfm_result.rb', line 134 def max_repeats @max_repeats end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
134 135 136 |
# File 'lib/rfm_result.rb', line 134 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
134 135 136 |
# File 'lib/rfm_result.rb', line 134 def type @type end |
Instance Method Details
#coerce(value) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/rfm_result.rb', line 136 def coerce(value) return nil if (value == nil || value == '') && @result != "text" case @result when "text" return value when "number" return BigDecimal.new(value) when "date" (day, month, year) = /(\d\d)\/(\d\d)\/(\d+)/.match(value) return Date.new(year.to_i, month.to_i, day.to_i) when "time" (hour, min, sec) = /(\d+):(\d+):(\d+)/.match(value) return DateTime.civil(-4712, 1, 1, hour.to_i, min.to_i, sec.to_i) when "timestamp" (month, day, year, hour, min, sec) = /(\d+)\/(\d+)\/(\d+)\s+(\d+):(\d+):(\d+)/.match(value) return DateTime.civil(year.to_i, month.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i) end end |