Class: Filemaker::Metadata::Field
- Inherits:
-
Object
- Object
- Filemaker::Metadata::Field
- Defined in:
- lib/filemaker/metadata/field.rb
Instance Attribute Summary collapse
-
#data_type ⇒ String
readonly
‘timestamp’, or ‘container’.
-
#field_type ⇒ String
readonly
One of ‘normal’, ‘calculation’, or ‘summary’.
-
#global ⇒ Boolean
readonly
Whether it is a global field.
-
#name ⇒ String
readonly
Name of the field.
-
#repeats ⇒ Integer
readonly
How many times the <data> repeats.
-
#required ⇒ Boolean
readonly
Indicates if field is required or not.
Instance Method Summary collapse
- #coerce(value) ⇒ Object
-
#initialize(definition, resultset) ⇒ Field
constructor
A new instance of Field.
-
#remove_decimal_mark(value) ⇒ Object
Remove dollar sign also.
Constructor Details
#initialize(definition, resultset) ⇒ Field
Returns a new instance of Field.
26 27 28 29 30 31 32 33 34 |
# File 'lib/filemaker/metadata/field.rb', line 26 def initialize(definition, resultset) @name = definition['name'] @data_type = definition['result'] @field_type = definition['type'] @repeats = definition['max-repeat'].to_i @global = convert_to_boolean(definition['global']) @required = convert_to_boolean(definition['not-empty']) @resultset = resultset end |
Instance Attribute Details
#data_type ⇒ String (readonly)
‘timestamp’, or ‘container’
12 13 14 |
# File 'lib/filemaker/metadata/field.rb', line 12 def data_type @data_type end |
#field_type ⇒ String (readonly)
Returns one of ‘normal’, ‘calculation’, or ‘summary’.
15 16 17 |
# File 'lib/filemaker/metadata/field.rb', line 15 def field_type @field_type end |
#global ⇒ Boolean (readonly)
Returns whether it is a global field.
24 25 26 |
# File 'lib/filemaker/metadata/field.rb', line 24 def global @global end |
#name ⇒ String (readonly)
Returns name of the field.
8 9 10 |
# File 'lib/filemaker/metadata/field.rb', line 8 def name @name end |
#repeats ⇒ Integer (readonly)
Returns how many times the <data> repeats.
18 19 20 |
# File 'lib/filemaker/metadata/field.rb', line 18 def repeats @repeats end |
#required ⇒ Boolean (readonly)
Returns indicates if field is required or not.
21 22 23 |
# File 'lib/filemaker/metadata/field.rb', line 21 def required @required end |
Instance Method Details
#coerce(value) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/filemaker/metadata/field.rb', line 41 def coerce(value) value = value.to_s.strip return nil if value.empty? case data_type when 'number' BigDecimal.new(remove_decimal_mark(value)) when 'date' # date_format likely will be '%m/%d/%Y', but if we got '19/8/2014', # then `strptime` will raise invalid date error # Sometimes we can get '27/11 /1981' also :( begin Date.strptime(value, @resultset.date_format) rescue StandardError # We could be getting back these date: # '17.12.95', '19/05/99', '27/11 /1981' # '1959-07-03' will be beyond us, so consider returning exact value value = value.gsub(/-|\./, '/') split = value.split('/').map(&:strip) split[2] = "19#{split[2]}" if split[2].size == 2 value = split.join('/') Date.strptime( Date.parse(value) .strftime(@resultset.date_format), @resultset.date_format ) end when 'time' DateTime.strptime("1/1/-4712 #{value}", @resultset.) when 'timestamp' DateTime.strptime(value, @resultset.) when 'container' # container may return value that include URI scheme already return URI.parse(value) if value.start_with?('http') URI.parse("#{@resultset.server.url}#{value}") else value end rescue StandardError warn "Could not coerce #{name}: #{value}" value end |
#remove_decimal_mark(value) ⇒ Object
Remove dollar sign also
37 38 39 |
# File 'lib/filemaker/metadata/field.rb', line 37 def remove_decimal_mark(value) value.delete('$,') end |