Class: Terrazine::Row

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/terrazine/result.rb

Overview

respresent result row

Direct Known Subclasses

Result

Instance Method Summary collapse

Constructor Details

#initialize(pg_result, values) ⇒ Row

attr_reader :pg_result, :values



8
9
10
11
12
13
14
# File 'lib/terrazine/result.rb', line 8

def initialize(pg_result, values)
  # @pg_result = pg_result
  # @values = values
  # Hiding from console a lot of data lines-_- ... another method?
  define_singleton_method(:pg_result) { pg_result }
  define_singleton_method(:values) { values }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *_) ⇒ Object



20
21
22
23
24
25
# File 'lib/terrazine/result.rb', line 20

def method_missing(method_name, *_)
  indx = index(method_name.to_s)
  indx || super
  return unless values
  values[indx]
end

Instance Method Details

#respond_to_missing?(method_name, include_all = true) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/terrazine/result.rb', line 16

def respond_to_missing?(method_name, include_all = true)
  index(method_name.to_s) || super
end

#to_hObject



27
28
29
30
# File 'lib/terrazine/result.rb', line 27

def to_h
  return {} unless values.present?
  pg_result.fields.zip(values).to_h
end