Class: RFilemaker::Field
- Inherits:
-
Object
- Object
- RFilemaker::Field
- Defined in:
- lib/rfilemaker/field.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Name of the field.
-
#type ⇒ Object
readonly
Type of the field as symbol.
Instance Method Summary collapse
-
#coerce(value) ⇒ Object
Coerce a value to the Ruby equivalent of the Filemaker Type.
-
#initialize(xml, result_set) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(xml, result_set) ⇒ Field
Returns a new instance of Field.
8 9 10 11 12 13 |
# File 'lib/rfilemaker/field.rb', line 8 def initialize(xml, result_set) @name = xml['NAME'] @type = xml['TYPE'] ? xml['TYPE'].downcase.to_sym : :none @empty_ok = xml['EMPTYOK'] == 'YES' @result_set = result_set end |
Instance Attribute Details
#name ⇒ Object (readonly)
Name of the field
4 5 6 |
# File 'lib/rfilemaker/field.rb', line 4 def name @name end |
#type ⇒ Object (readonly)
Type of the field as symbol
6 7 8 |
# File 'lib/rfilemaker/field.rb', line 6 def type @type end |
Instance Method Details
#coerce(value) ⇒ Object
Coerce a value to the Ruby equivalent of the Filemaker Type
-
‘DATE’ gets converted to Date
-
‘TIME’ gets converted to DateTime
-
‘TIMESTAMP’ gets converted to DateTime
-
‘NUMBER’ gets converted to float or integer
-
everything else gets converted to a string
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rfilemaker/field.rb', line 22 def coerce(value) return nil if value.nil? || value == '' case type when :date Date.strptime(value, @result_set.date_format) unless @empty_ok when :time DateTime.strptime("1/1/-4712 #{value}", @result_set.time_format) unless @empty_ok when :timestamp DateTime.strptime(value, @result_set.time_format) unless @empty_ok when :number if value.include?('.') value.to_f elsif value.include?(',') value.gsub(/,/, '.').to_f else value.to_i end else value.to_s end end |