Class: RFilemaker::ResultSet

Inherits:
Array
  • Object
show all
Defined in:
lib/rfilemaker/result_set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ ResultSet

Generates a new ResultSet (or plain Ruby Array) for the given XML document Items in the ResultSet are Hashes, representing rows in the Filemaker export



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rfilemaker/result_set.rb', line 14

def initialize(doc)
  @fields = extract_fields(doc)
  @rows   = extract_rows(doc)

  d = doc.css('DATABASE')
  @date_format = ResultSet.parse_date_format(d.attribute('DATEFORMAT').to_s)
  @time_format = ResultSet.parse_date_format(d.attribute('TIMEFORMAT').to_s)
        
  @rows.each do |row|
    self << Record.new(row, fields)
  end
end

Instance Attribute Details

#date_formatObject (readonly)

Returns the value of attribute date_format.



10
11
12
# File 'lib/rfilemaker/result_set.rb', line 10

def date_format
  @date_format
end

#fieldsObject (readonly)

Returns the value of attribute fields.



9
10
11
# File 'lib/rfilemaker/result_set.rb', line 9

def fields
  @fields
end

#rowsObject (readonly)

Returns the value of attribute rows.



9
10
11
# File 'lib/rfilemaker/result_set.rb', line 9

def rows
  @rows
end

#time_formatObject (readonly)

Returns the value of attribute time_format.



10
11
12
# File 'lib/rfilemaker/result_set.rb', line 10

def time_format
  @time_format
end

Class Method Details

.parse_date_format(string) ⇒ Object

Parse a Filemaker date format to something strptime understands



4
5
6
7
# File 'lib/rfilemaker/result_set.rb', line 4

def self.parse_date_format(string)
  string = string.gsub(/yyyy|yy/, '%y').gsub(/mm|m|MM|M/, '%m').gsub(/dd|d|DD|D/, '%d')
  string.gsub(/hh|h/, '%I').gsub(/kk|k/, '%H').gsub(/mm/, '%M').gsub(/ss/, '%S').gsub(/a/, '%p')
end