Class: Filemaker::Resultset

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/filemaker/resultset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, xml, params = nil) ⇒ Resultset

Returns a new instance of Resultset.

Parameters:

  • server (Filemaker::Server)
  • xml (String)

    The XML string from response

  • params (Hash) (defaults to: nil)

    The request params used to construct request



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
# File 'lib/filemaker/resultset.rb', line 44

def initialize(server, xml, params = nil)
  @list = []
  @fields = {}
  @portal_fields = {}
  @server = server
  @params = params # Useful for debugging

  doc = Nokogiri::XML(xml).remove_namespaces!
  @xml = doc.to_xml(indent: 2) # Just want to pretty print it

  error_code = doc.xpath('/fmresultset/error').attribute('code').value.to_i
  raise_potential_error!(error_code)

  datasource = doc.xpath('/fmresultset/datasource')
     = doc.xpath('/fmresultset/metadata')
  resultset  = doc.xpath('/fmresultset/resultset')
  records    = resultset.xpath('record')

  @date_format = convert_format(datasource.attribute('date-format').value)
  @time_format = convert_format(datasource.attribute('time-format').value)
  @timestamp_format = \
    convert_format(datasource.attribute('timestamp-format').value)

  @count = resultset.attribute('count').value.to_i
  @total_count = datasource.attribute('total-count').value.to_i

  ()
  build_records(records)
end

Instance Attribute Details

#countInteger (readonly)

Returns number of records.

Returns:

  • (Integer)

    number of records



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

def count
  @count
end

#date_formatString (readonly)

Returns Ruby’s date format directive.

Returns:

  • (String)

    Ruby’s date format directive



24
25
26
# File 'lib/filemaker/resultset.rb', line 24

def date_format
  @date_format
end

#fieldsHash (readonly)

Returns representing the top-level non-portal field-definition.

Returns:

  • (Hash)

    representing the top-level non-portal field-definition



18
19
20
# File 'lib/filemaker/resultset.rb', line 18

def fields
  @fields
end

#listArray (readonly)

Returns hold records.

Returns:

  • (Array)

    hold records



9
10
11
# File 'lib/filemaker/resultset.rb', line 9

def list
  @list
end

#paramsHash (readonly)

Returns the request params.

Returns:

  • (Hash)

    the request params



36
37
38
# File 'lib/filemaker/resultset.rb', line 36

def params
  @params
end

#portal_fieldsHash (readonly)

Returns representing the portal field-definition.

Returns:

  • (Hash)

    representing the portal field-definition



21
22
23
# File 'lib/filemaker/resultset.rb', line 21

def portal_fields
  @portal_fields
end

#serverFilemaker::Server (readonly)

Returns the server.

Returns:



33
34
35
# File 'lib/filemaker/resultset.rb', line 33

def server
  @server
end

#time_formatString (readonly)

Returns Ruby’s time format directive.

Returns:

  • (String)

    Ruby’s time format directive



27
28
29
# File 'lib/filemaker/resultset.rb', line 27

def time_format
  @time_format
end

#timestamp_formatString (readonly)

Returns Ruby’s date and time format directive.

Returns:

  • (String)

    Ruby’s date and time format directive



30
31
32
# File 'lib/filemaker/resultset.rb', line 30

def timestamp_format
  @timestamp_format
end

#total_countInteger (readonly)

Returns total count of the record.

Returns:

  • (Integer)

    total count of the record



15
16
17
# File 'lib/filemaker/resultset.rb', line 15

def total_count
  @total_count
end

#xmlString (readonly)

Returns the raw XML for inspection.

Returns:

  • (String)

    the raw XML for inspection



39
40
41
# File 'lib/filemaker/resultset.rb', line 39

def xml
  @xml
end

Instance Method Details

#each(*args, &block) ⇒ Object

Delegate to list -> map, filter, reverse, etc



75
76
77
# File 'lib/filemaker/resultset.rb', line 75

def each(*args, &block)
  list.each(*args, &block)
end

#sizeObject Also known as: length



79
80
81
# File 'lib/filemaker/resultset.rb', line 79

def size
  list.size
end