Sha256: fe3ed9c204d79988a33de10953a3be1143943c0db0becffe9ee159b66b68a428

Contents?: true

Size: 692 Bytes

Versions: 7

Compression:

Stored size: 692 Bytes

Contents

require 'csv'
require 'csb/cols'

module Csb
  class Builder
    UTF8_BOM = "\xEF\xBB\xBF".freeze

    attr_reader :output, :utf8_bom, :items, :cols
    attr_accessor :items

    def initialize(output = '', items: [], utf8_bom: false)
      @output = output
      @utf8_bom = utf8_bom
      @cols = Cols.new
      @items = items
    end

    def build
      output << UTF8_BOM if utf8_bom
      output << CSV.generate_line(cols.headers)
      items.each do |item|
        output << CSV.generate_line(cols.values_by_item(item))
      rescue => error
        break if Csb.configuration.ignore_class_names.include?(error.class.name)

        raise error
      end
      output
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
csb-0.7.0 lib/csb/builder.rb
csb-0.6.0 lib/csb/builder.rb
csb-0.5.1 lib/csb/builder.rb
csb-0.5.0 lib/csb/builder.rb
csb-0.4.0 lib/csb/builder.rb
csb-0.3.1 lib/csb/builder.rb
csb-0.3.0 lib/csb/builder.rb