class CSVConv::Converter

Converter from CSV

Public Class Methods

new(format, options) click to toggle source
# File lib/csvconv/converter.rb, line 4
def initialize(format, options)
  @format = format
  @sep = options[:sep] || ','
  @header = options[:header]
end

Public Instance Methods

convert(input) click to toggle source
# File lib/csvconv/converter.rb, line 10
def convert(input)
  @header ||= Parser.read_header(input, @sep)
  hash_array = []
  while (line = input.gets)
    hash_array << Parser.parse_line(line, @header, @sep)
  end
  Formatter.send(@format, hash_array)
end
convert_stream(input, output) click to toggle source
# File lib/csvconv/converter.rb, line 19
def convert_stream(input, output)
  @header ||= Parser.read_header(input, @sep)
  while (line = input.gets)
    hash = Parser.parse_line(line, @header, @sep)
    output.puts Formatter.send(@format, [hash])
  end
end