masa21kik/csvconv

View on GitHub
lib/csvconv/parser.rb

Summary

Maintainability
A
0 mins
Test Coverage
require "csv"

module Csvconv
  # Parse CSV to Hash
  module Parser
    def read_header(input, sep)
      CSV.parse_line(input.gets, col_sep: sep)
    end

    def parse_line(input, header, sep)
      Hash[header.zip(CSV.parse_line(input, col_sep: sep))]
    end

    module_function :read_header, :parse_line
  end
end