Class: OpenEHR::AQL::ResultSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/openehr/aql/result_set.rb

Overview

The output of Query#execute: column names plus rows (each row is an Array positionally aligned with columns).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(columns:, rows:) ⇒ ResultSet

Returns a new instance of ResultSet.



13
14
15
16
17
# File 'lib/openehr/aql/result_set.rb', line 13

def initialize(columns:, rows:)
  @columns = columns.freeze
  @rows = rows.freeze
  freeze
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



11
12
13
# File 'lib/openehr/aql/result_set.rb', line 11

def columns
  @columns
end

#rowsObject (readonly)

Returns the value of attribute rows.



11
12
13
# File 'lib/openehr/aql/result_set.rb', line 11

def rows
  @rows
end

Instance Method Details

#eachObject



19
20
21
22
23
# File 'lib/openehr/aql/result_set.rb', line 19

def each
  return enum_for(:each) unless block_given?

  rows.each { |row| yield row }
end

#sizeObject



25
26
27
# File 'lib/openehr/aql/result_set.rb', line 25

def size
  rows.size
end

#to_json(*args) ⇒ Object

The openEHR REST Query API's result-set shape (columns/rows), scoped to what's useful here rather than every optional metadata field ("meta", "name", "q", ...) the full spec allows - add them if/when a caller needs them. Each RM object row value is expanded via RMJSONSerializer; JSON primitives (String/Numeric/ true/false/nil) pass through unchanged.



35
36
37
38
39
40
# File 'lib/openehr/aql/result_set.rb', line 35

def to_json(*args)
  {
    'columns' => columns.map { |name| { 'name' => name } },
    'rows' => rows.map { |row| row.map { |value| json_value(value) } }
  }.to_json(*args)
end