Sha256: 7bb00e3fdd70e90bb286b08519f86dc75ddb4306f1ccb74589eef9380c7ebf2e

Contents?: true

Size: 832 Bytes

Versions: 8

Compression:

Stored size: 832 Bytes

Contents

module Alf
  module Support
    #
    # Provides common tooling to CSV renderer and readers
    #
    module CSVUtils

      DEFAULT_OPTIONS = {
        :headers => true
      }

      private

      # Returns a CSV instance bound to a given io and options
      def get_csv(io, options = {})
        require 'csv'
        ::CSV.new io, Tuple(options).project(::CSV::DEFAULT_OPTIONS.keys)
      end

      # Yields a CSV instance bound to a given io and options
      def with_csv(io, options = {})
        yield get_csv(io, options)
      end

      class ProcIO

        def initialize(proc = nil, &bl)
          @proc = proc || bl
        end

        def call(*args, &bl)
          @proc.call(*args, &bl)
        end
        alias :<< :call

      end # ProcIO

    end # module CSVUtils
  end # module Support
end # module Alf

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
alf-core-0.16.3 lib/alf/support/csv_utils.rb
alf-core-0.16.2 lib/alf/support/csv_utils.rb
alf-core-0.16.1 lib/alf/support/csv_utils.rb
alf-core-0.16.0 lib/alf/support/csv_utils.rb
alf-core-0.15.0 lib/alf/support/csv_utils.rb
alf-core-0.14.0 lib/alf-io/alf/support/csv_utils.rb
alf-core-0.13.1 lib/alf-io/alf/support/csv_utils.rb
alf-core-0.13.0 lib/alf-io/alf/support/csv_utils.rb