Sha256: b4cfdab08b41d04590472c9ba4fa0868a27a1ed779b0f358858f1456a472ab31

Contents?: true

Size: 939 Bytes

Versions: 1

Compression:

Stored size: 939 Bytes

Contents

module IOStreams
  class Tabular
    module Parser
      class Csv < Base
        attr_reader :csv_parser

        def initialize
          @csv_parser = Utility::CSVRow.new
        end

        # Returns [Array<String>] the header row.
        # Returns nil if the row is blank.
        def parse_header(row)
          raise(Tabular::Errors::InvalidHeader, "Format is :csv. Invalid input header: #{row.class.name}") unless row.is_a?(String)

          csv_parser.parse(row)
        end

        # Returns [Array] the parsed CSV line
        def parse(row)
          raise(Tabular::Errors::TypeMismatch, "Format is :csv. Invalid input: #{row.class.name}") unless row.is_a?(String)

          csv_parser.parse(row)
        end

        # Return the supplied array as a single line CSV string.
        def render(row, header)
          array = header.to_array(row)
          csv_parser.to_csv(array)
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
iostreams-0.15.0 lib/io_streams/tabular/parser/csv.rb