Class: Simple::SQL::Decoder::Record

Inherits:
MultiColumns show all
Defined in:
lib/simple/sql/decoder.rb

Instance Method Summary collapse

Constructor Details

#initialize(result, into:) ⇒ Record

Returns a new instance of Record.



97
98
99
100
101
102
103
# File 'lib/simple/sql/decoder.rb', line 97

def initialize(result, into:)
  super(result)

  @into = into
  @result = result
  @field_names = @result.fields.map(&:to_sym)
end

Instance Method Details

#decode(row) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/simple/sql/decoder.rb', line 105

def decode(row)
  decoded_row = super(row)
  hsh = Hash[@field_names.zip(decoded_row)]
  if @into && @into != Hash
    @into.new(hsh)
  else
    hsh
  end
end