Class: Filemaker::Record

Inherits:
HashWithIndifferentAndCaseInsensitiveAccess show all
Defined in:
lib/filemaker/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HashWithIndifferentAndCaseInsensitiveAccess

#delete, #fetch, #key?, #values_at

Constructor Details

#initialize(record, resultset, portal_table_name = nil) ⇒ Record



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/filemaker/record.rb', line 14

def initialize(record, resultset, portal_table_name = nil)
  @mod_id    = record['mod-id']
  @record_id = record['record-id']
  @portals   = HashWithIndifferentAndCaseInsensitiveAccess.new
  @dirty     = {} # Keep track of field modification
  @ready     = false

  record.xpath('field').each do |field|
    # `field` is Nokogiri::XML::Element
    field_name = field['name']
    # Right now, I do not want to mess with the field name
    # field_name.gsub!(Regexp.new(portal_table_name + '::'), '')
    #   \if portal_table_name
    datum = []

     = if portal_table_name
                        resultset.portal_fields[portal_table_name]
                      else
                        resultset.fields
                      end

    field.xpath('data').each do |data|
      datum.push([field_name].coerce(data.inner_text))
    end

    self[field_name] = normalize_data(datum)
  end

  build_portals(record.xpath('relatedset'), resultset)

  @ready = true
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object (private)



86
87
88
89
90
91
# File 'lib/filemaker/record.rb', line 86

def method_missing(symbol, *args, &block)
  method = symbol.to_s
  return self[method] if key?(method)
  return @dirty[$`] = args.first if method =~ /(=)$/ && key?($`)
  super
end

Instance Attribute Details

#dirtyObject (readonly)

Returns the value of attribute dirty.



12
13
14
# File 'lib/filemaker/record.rb', line 12

def dirty
  @dirty
end

#mod_idString (readonly)



4
5
6
# File 'lib/filemaker/record.rb', line 4

def mod_id
  @mod_id
end

#portalsHash (readonly)



10
11
12
# File 'lib/filemaker/record.rb', line 10

def portals
  @portals
end

#record_idString (readonly)



7
8
9
# File 'lib/filemaker/record.rb', line 7

def record_id
  @record_id
end

Instance Method Details

#[](key) ⇒ Object



47
48
49
50
51
# File 'lib/filemaker/record.rb', line 47

def [](key)
  raise(Filemaker::Errors::InvalidFieldError, "Invalid field: #{key}") \
    unless key?(key)
  super
end

#[]=(key, value) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/filemaker/record.rb', line 53

def []=(key, value)
  if @ready
    raise(Filemaker::Errors::InvalidFieldError, "Invalid field: #{key}") \
    unless key?(key)
    @dirty[key] = value
  else
    super
  end
end