Class: Rfm::Resultset
- Inherits:
-
Array
- Object
- Array
- Rfm::Resultset
- Defined in:
- lib/rfm/resultset.rb
Overview
The ResultSet object represents a set of records in FileMaker. It is, in every way, a real Ruby Array, so everything you expect to be able to do with an Array can be done with a ResultSet as well. In this case, the elements in the array are Record objects.
Here’s a typical example, displaying the results of a Find:
myServer = Rfm::Server.new(...)
results = myServer["Customers"]["Details"].find("First Name" => "Bill")
results.each {|record|
puts record["First Name"]
puts record["Last Name"]
puts record["Email Address"]
}
Attributes
The ResultSet object has these attributes:
-
field_meta is a hash with field names for keys and Field objects for values; it provides info about the fields in the ResultSet
-
portal_meta is a hash with table occurrence names for keys and arrays of Field objects for values; it provides metadata about the portals in the ResultSet and the Fields on those portals
Instance Attribute Summary collapse
-
#date_format ⇒ Object
readonly
Returns the value of attribute date_format.
-
#field_meta ⇒ Object
readonly
Returns the value of attribute field_meta.
-
#foundset_count ⇒ Object
readonly
Returns the value of attribute foundset_count.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#portal_meta ⇒ Object
readonly
Returns the value of attribute portal_meta.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#time_format ⇒ Object
readonly
Returns the value of attribute time_format.
-
#timestamp_format ⇒ Object
readonly
Returns the value of attribute timestamp_format.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
-
#initialize(server, xml_response, layout, portals = nil) ⇒ Resultset
constructor
Initializes a new ResultSet object.
Constructor Details
#initialize(server, xml_response, layout, portals = nil) ⇒ Resultset
Initializes a new ResultSet object. You will probably never do this your self (instead, use the Layout object to get various ResultSet obejects).
If you feel so inclined, though, pass a Server object, and some fmpxmlresult
compliant XML in a String.
Attributes
The ResultSet object includes several useful attributes:
-
fields is a hash (with field names for keys and Field objects for values). It includes an entry for every field in the ResultSet. Note: You don’t use Field objects to access data. If you’re after data, get a Record object (ResultSet is an array of records). Field objects tell you about the fields (their type, repetitions, and so forth) in case you find that information useful programmatically.
Note: keys in the
fields
hash are downcased for convenience (and [] automatically downcases on lookup, so it should be seamless). But if youeach
a field hash and need to know a field’s real name, with correct case, domyField.name
instead of relying on the key in the hash. -
portals is a hash (with table occurrence names for keys and Field objects for values). If your layout contains portals, you can find out what fields they contain here. Again, if it’s the data you’re after, you want to look at the Record object.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rfm/resultset.rb', line 68 def initialize(server, xml_response, layout, portals=nil) @layout = layout @server = server @field_meta ||= Rfm::CaseInsensitiveHash.new @portal_meta ||= Rfm::CaseInsensitiveHash.new @include_portals = portals doc = Nokogiri.XML(remove_namespace(xml_response)) error = doc.xpath('/fmresultset/error').attribute('code').value.to_i check_for_errors(error, server.state[:raise_on_401]) datasource = doc.xpath('/fmresultset/datasource') = doc.xpath('/fmresultset/metadata') resultset = doc.xpath('/fmresultset/resultset') @date_format = convert_date_time_format(datasource.attribute('date-format').value) @time_format = convert_date_time_format(datasource.attribute('time-format').value) @timestamp_format = convert_date_time_format(datasource.attribute('timestamp-format').value) @foundset_count = resultset.attribute('count').value.to_i @total_count = datasource.attribute('total-count').value.to_i parse_fields() parse_portals() if @include_portals Rfm::Record.build_records(resultset.xpath('record'), self, @field_meta, @layout) end |
Instance Attribute Details
#date_format ⇒ Object (readonly)
Returns the value of attribute date_format.
43 44 45 |
# File 'lib/rfm/resultset.rb', line 43 def date_format @date_format end |
#field_meta ⇒ Object (readonly)
Returns the value of attribute field_meta.
42 43 44 |
# File 'lib/rfm/resultset.rb', line 42 def @field_meta end |
#foundset_count ⇒ Object (readonly)
Returns the value of attribute foundset_count.
44 45 46 |
# File 'lib/rfm/resultset.rb', line 44 def foundset_count @foundset_count end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
41 42 43 |
# File 'lib/rfm/resultset.rb', line 41 def layout @layout end |
#portal_meta ⇒ Object (readonly)
Returns the value of attribute portal_meta.
42 43 44 |
# File 'lib/rfm/resultset.rb', line 42 def @portal_meta end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
41 42 43 |
# File 'lib/rfm/resultset.rb', line 41 def server @server end |
#time_format ⇒ Object (readonly)
Returns the value of attribute time_format.
43 44 45 |
# File 'lib/rfm/resultset.rb', line 43 def time_format @time_format end |
#timestamp_format ⇒ Object (readonly)
Returns the value of attribute timestamp_format.
43 44 45 |
# File 'lib/rfm/resultset.rb', line 43 def @timestamp_format end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
44 45 46 |
# File 'lib/rfm/resultset.rb', line 44 def total_count @total_count end |