Class: HasherizeCsv::Csv

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hasherize_csv.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, opts = {}) ⇒ Csv

Returns a new instance of Csv.



12
13
14
15
16
17
18
# File 'lib/hasherize_csv.rb', line 12

def initialize file, opts = {}
  @file = file
  @separator = opts[:separator] || DefaultOpts::DEFAULT[:separator]
  @value_pattern = opts[:value_pattern] || DefaultOpts::DEFAULT[:value_pattern]
  @keys = []
  @keys =  values_from_line next_line 
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



11
12
13
# File 'lib/hasherize_csv.rb', line 11

def file
  @file
end

#keysObject

Returns the value of attribute keys.



11
12
13
# File 'lib/hasherize_csv.rb', line 11

def keys
  @keys
end

#separatorObject

Returns the value of attribute separator.



11
12
13
# File 'lib/hasherize_csv.rb', line 11

def separator
  @separator
end

Instance Method Details

#eachObject



20
21
22
23
24
25
26
# File 'lib/hasherize_csv.rb', line 20

def each
  return self.to_enum if !block_given?

  until (hash = next_item).nil?
    yield hash
  end 
end