Class: Rseed::HashAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/rseed/hash_adapter.rb

Instance Attribute Summary collapse

Attributes inherited from Adapter

#converter, #error, #logger, #options

Instance Method Summary collapse

Methods inherited from Adapter

#converter_attributes, #mandatory_attributes

Constructor Details

#initialize(data = nil) ⇒ HashAdapter

Returns a new instance of HashAdapter.



4
5
6
# File 'lib/rseed/hash_adapter.rb', line 4

def initialize data = nil
  @data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/rseed/hash_adapter.rb', line 3

def data
  @data
end

Instance Method Details

#preprocessObject



8
9
10
11
12
# File 'lib/rseed/hash_adapter.rb', line 8

def preprocess
  return false unless @data.is_a? Array or @data.is_a?(Hash)
  @data = [@data] if @data.is_a?(Hash)
  true
end

#process(&block) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/rseed/hash_adapter.rb', line 14

def process &block
  meta = {}
  meta[:total_records] = @data.length
  @data.each_with_index do |d, i|
    meta[:record_count] = i + 1
    yield d, meta
  end
end