Class: Simple::SQL::Helpers::RowConverter::TypeConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/simple/sql/helpers/row_converter.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:) ⇒ TypeConverter



28
29
30
# File 'lib/simple/sql/helpers/row_converter.rb', line 28

def initialize(type:)
  @type = type
end

Class Method Details

.for(type:) ⇒ Object



24
25
26
# File 'lib/simple/sql/helpers/row_converter.rb', line 24

def self.for(type:)
  new(type: type)
end

Instance Method Details

#convert_ary(hsh) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/simple/sql/helpers/row_converter.rb', line 32

def convert_ary(hsh)
  updates = {}
  hsh.each do |key, value|
    case value
    when Hash   then updates[key] = SELF.convert(value, into: @type)
    when Array  then updates[key] = SELF.convert_ary(value, into: @type)
    end
  end

  hsh = hsh.merge(updates)

  @type.new hsh
end