Class: LineParser

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

Instance Method Summary collapse

Constructor Details

#initialize(keys, &line_response_block) ⇒ LineParser

Returns a new instance of LineParser.



210
211
212
213
# File 'lib/ebutil.rb', line 210

def initialize(keys, &line_response_block)
  @keys = keys
  @line_response_block = line_response_block
end

Instance Method Details

#parse(lines) ⇒ Object



215
216
217
# File 'lib/ebutil.rb', line 215

def parse(lines)
  lines.each { |line| parse_line(line) }
end

#parse_line(line) ⇒ Object



219
220
221
222
223
224
225
226
227
# File 'lib/ebutil.rb', line 219

def parse_line(line)
  line.strip!
  attributes = {}
  line.split('","').each_with_index do |cell, index|
    cell = cell.unquote
    attributes[keys[index]] = cell if keys.has_key?(index)
  end
  line_response_block.call attributes
end