Module: Conformist::Base

Defined in:
lib/conformist/base.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/conformist/base.rb', line 3

def self.included base
  base.class_eval do
    extend ClassMethods
    
    attr_accessor :path
  end
end

Instance Method Details

#foreach(&block) ⇒ Object

Enumerate over each row in the input file.

Example:

input1 = Input1.load 'input1.csv'
input1.foreach do |row|
  Model.create! row
end

Returns nothing.



21
22
23
24
25
# File 'lib/conformist/base.rb', line 21

def foreach &block
  CSV.foreach(path, self.class.options) do |row| 
    yield Row.new(self.class.columns, row).to_hash
  end
end