Class: Rfm::Result::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/rfm_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#globalObject (readonly)

Returns the value of attribute global.



134
135
136
# File 'lib/rfm_result.rb', line 134

def global
  @global
end

#max_repeatsObject (readonly)

Returns the value of attribute max_repeats.



134
135
136
# File 'lib/rfm_result.rb', line 134

def max_repeats
  @max_repeats
end

#nameObject (readonly)

Returns the value of attribute name.



134
135
136
# File 'lib/rfm_result.rb', line 134

def name
  @name
end

#typeObject (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