Class: Trophonius::RecordSet

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

Overview

A RecordSet contains all records, as Record, retrieved from the FileMaker database

Defined Under Namespace

Classes: EmptyParameterError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(l_name, nmf) ⇒ RecordSet

Initializes a new RecordSet

Parameters:

  • l_name: (String)

    name of the FileMaker layout

  • nmf: (Array)

    names of the fields that cannot be modified (calculation fields etc.)



19
20
21
22
23
# File 'lib/trophonius_recordset.rb', line 19

def initialize(l_name, nmf)
  self.layout_name = l_name
  self.non_modifiable_fields = nmf
  self.records = []
end

Instance Attribute Details

#layout_nameObject

Returns the value of attribute layout_name.



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

def layout_name
  @layout_name
end

#non_modifiable_fieldsObject

Returns the value of attribute non_modifiable_fields.



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

def non_modifiable_fields
  @non_modifiable_fields
end

#recordsObject

Returns the value of attribute records.



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

def records
  @records
end

#result_countObject

Returns the value of attribute result_count.



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

def result_count
  @result_count
end

Instance Method Details

#<<(data) ⇒ Object



25
26
27
28
# File 'lib/trophonius_recordset.rb', line 25

def <<(data)
  records << data
  super
end

#paginate(page, records_per_page) ⇒ RecordSet

This method chops the RecordSet up in parts.

Parameters:

  • page: (Integer)

    the current page

  • records_per_page: (Integer)

    the amount of records on the page

Returns:

  • (RecordSet)

    the records in the range ((page * records_per_page) - records_per_page) + 1 until ((page * records_per_page) - records_per_page) + 1 + records_per_page



53
54
55
56
# File 'lib/trophonius_recordset.rb', line 53

def paginate(page, records_per_page)
  offset = ((page * records_per_page) - records_per_page)
  records[offset...offset + records_per_page]
end

#where(fielddata) ⇒ RecordSet

This method allows to chain where statements

Parameters:

  • fielddata: (Hash)

    hash containing the query

Returns:

  • (RecordSet)

    the records where the statement holds

Raises:



36
37
38
39
40
41
42
43
# File 'lib/trophonius_recordset.rb', line 36

def where(fielddata)
  raise EmptyParameterError.new, 'No requested data to find' if fielddata.nil? || fielddata.empty?

  temp = Trophonius::Model
  temp.config layout_name: layout_name, non_modifiable_fields: non_modifiable_fields
  retval = temp.where(fielddata)
  retval
end