Sha256: 7644e10a307661767f538bd0a91be49a43fdd17c2fd14bea9acc90ddf252cbf7

Contents?: true

Size: 568 Bytes

Versions: 5

Compression:

Stored size: 568 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))
      end
      output
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
csb-0.2.4 lib/csb/builder.rb
csb-0.2.3 lib/csb/builder.rb
csb-0.2.2 lib/csb/builder.rb
csb-0.2.1 lib/csb/builder.rb
csb-0.2.0 lib/csb/builder.rb