Sha256: 9ec6255ddea4367a3a3bbaaed3c77b26c071094a4843229e3a2e7d882bee6fb6

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

require 'oj'
Oj.default_options = { mode: :compat }

require_relative './csvpp/version'
require_relative './csvpp/os'
require_relative './csvpp/conversions'
require_relative './csvpp/format'
require_relative './csvpp/parser'
require_relative './csvpp/sqlite_importer'
require_relative './csvpp/formats_client'

module CSVPP
  DEFAULT_COL_SEP = '|'

  # @param input [String] path to input file
  # @param format [String, Format] path to format file
  # @param col_sep [String]
  #
  # @return [Array<Object>]
  def self.parse(input:,
                 format:,
                 col_sep: DEFAULT_COL_SEP,
                 convert_type: true,
                 &block)

    Parser.parse(
      input: input,
      format: Format.load(format),
      col_sep: col_sep,
      convert_type: convert_type,
      &block
    )
  end

  # @param input [String] input string
  # @param format [String, Format] format string
  # @param col_sep [String]
  #
  # @return [Array<Object>]
  def self.parse_str(input:,
                     format:,
                     col_sep: DEFAULT_COL_SEP,
                     convert_type: true,
                     &block)

    Parser.parse_str(
      input: input,
      format: Format.load_from_str(format),
      col_sep: col_sep,
      convert_type: convert_type,
      &block
    )
  end

  # @param input [String] input string
  # @param format [String, Format] format string
  # @param col_sep [String]
  #
  # @return [String]
  def self.json(input:,
                format:,
                convert_type: true,
                col_sep: DEFAULT_COL_SEP)
    h = {
      'vars' => parse_str(
        input: input,
        format: format,
        convert_type: convert_type,
        col_sep: col_sep
      )
    }

    Oj.dump(h)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csvpp-0.4.0 lib/csvpp.rb