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.



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

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

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

Instance Method Details

#decode(row) ⇒ Object



116
117
118
119
120
121
122
123
124
# File 'lib/simple/sql/decoder.rb', line 116

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