Class: GreenMonster::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/green_monster/decoder.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Decoder

初期化



4
5
6
# File 'lib/green_monster/decoder.rb', line 4

def initialize(schema)
  @schema = schema
end

Instance Method Details

#convert(row, &block) ⇒ Object

変換



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/green_monster/decoder.rb', line 9

def convert(row, &block)
  attrs = {}
  @schema.attributes.each do |attribute|
    attrs.update(
      attribute.name => attribute.decode(fetch_value(row[attribute.options[:col_num]]))
    )
  end

  block.call(attrs) if block_given?

  attrs
end