Class: Rfm::Result::Field

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

Overview

The Field object represents a single FileMaker field. It *does not hold the data* in the field. Instead, it serves as a source of metadata about the field. For example, if you’re script is trying to be highly dynamic about its field access, it may need to determine the data type of a field at run time. Here’s how:

field_name = "Some Field Name"
case myRecord.fields[field_name].result
when "text"
  # it is a text field, so handle appropriately
when "number"
  # it is a number field, so handle appropriately
end

Attributes

The Field object has the following attributes useful attributes:

  • name is the name of the field

  • result is the data type of the field; possible values include:

    • text

    • number

    • date

    • time

    • timestamp

    • container

  • type any of these:

    • normal (a normal data field)

    • calculation

    • summary

  • max_repeats is the number of repetitions (1 for a normal field, more for a repeating field)

  • global is true is this is a global field, false otherwise

Note: Field types match FileMaker’s own values, but the terminology differs. The result attribute tells you the data type of the field, regardless of whether it is a calculation, summary, or normal field. So a calculation field whose result type is timestamp would have these attributes:

  • result: timestamp

  • type: calculation

  • *control& is a FieldControl object representing the sytle and value list information associated with this field on the layout.

Note: Since a field can sometimes appear on a layout more than once, control may be an Array. If you don’t know ahead of time, you’ll need to deal with this. One easy way is:

controls = [myField.control].flatten
controls.each {|control|
  # do something with the control here
}

The code above makes sure the control is always an array. Typically, though, you’ll know up front if the control is an array or not, and you can code accordingly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result_set, field) ⇒ Field

Initializes a field object. You’ll never need to do this. Instead, get your Field objects from ResultSet::fields



391
392
393
394
395
396
397
398
399
400
# File 'lib/rfm_result.rb', line 391

def initialize(result_set, field)
  @result_set = result_set
  @name = field.attributes['name']
  @result = field.attributes['result']
  @type = field.attributes['type']
  @max_repeats = field.attributes['max-repeats']
  @global = field.attributes['global']
  
  @laded = false
end

Instance Attribute Details

#globalObject (readonly)

Returns the value of attribute global.



402
403
404
# File 'lib/rfm_result.rb', line 402

def global
  @global
end

#max_repeatsObject (readonly)

Returns the value of attribute max_repeats.



402
403
404
# File 'lib/rfm_result.rb', line 402

def max_repeats
  @max_repeats
end

#nameObject (readonly)

Returns the value of attribute name.



402
403
404
# File 'lib/rfm_result.rb', line 402

def name
  @name
end

#resultObject (readonly)

Returns the value of attribute result.



402
403
404
# File 'lib/rfm_result.rb', line 402

def result
  @result
end

#typeObject (readonly)

Returns the value of attribute type.



402
403
404
# File 'lib/rfm_result.rb', line 402

def type
  @type
end

Instance Method Details

#coerce(value) ⇒ Object

Coerces the text value from an fmresultset document into proper Ruby types based on the type of the field. You’ll never need to do this: Rfm does it automatically for you when you access field data through the Record object.



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/rfm_result.rb', line 411

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"
    return Date.strptime(value, @result_set.date_format)
  when "time"
    return DateTime.strptime("1/1/-4712 " + value, "%m/%d/%Y #{@result_set.time_format}")
  when "timestamp"
    return DateTime.strptime(value, @result_set.timestamp_format)
  when "container"
    return URI.parse("#{@result_set.server.scheme}://#{@result_set.server.host_name}:#{@result_set.server.port}#{value}")
  end
end

#controlObject



404
405
406
# File 'lib/rfm_result.rb', line 404

def control
  @result_set.layout.field_controls[@name]
end