Sha256: 388c44b11c1f3befee6b510aecf73505b83baa181ff7f7a5cf3a83a792f0b7e6

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

require 'csv'

require 'qb_iif/keywords'
require 'qb_iif/dsl/base'

require 'qb_iif/dsl/accnt'
require 'qb_iif/dsl/bud'
require 'qb_iif/dsl/ctype'
require 'qb_iif/dsl/cust'
require 'qb_iif/dsl/emp'
require 'qb_iif/dsl/invitem'
require 'qb_iif/dsl/invmemo'
require 'qb_iif/dsl/class'
require 'qb_iif/dsl/othername'
require 'qb_iif/dsl/paymeth'
require 'qb_iif/dsl/shipmeth'
require 'qb_iif/dsl/spl'
require 'qb_iif/dsl/terms'
require 'qb_iif/dsl/timeact'
require 'qb_iif/dsl/timerhdr'
require 'qb_iif/dsl/todo'
require 'qb_iif/dsl/trns'
require 'qb_iif/dsl/vend'
require 'qb_iif/dsl/vtype'

module QbIif
  class IIF
    include QbIif::Keywords

    def initialize(&block)
      @output = {}
      if block_given?
        if block.arity == 1
          yield(self)
        else
          instance_eval(&block)
        end
      end
    end

    def output
      CSV.generate(col_sep: "\t") do |tsv|

        @output.each do |_, list|
          list[:headers].uniq.each do |header|
            tsv << header
          end
          list[:rows].each do |row|
            tsv << row
          end
        end
      end
    end

    def method_missing(method_name, *args, &block)
      class_name = escaped(method_name).to_s.split('_').map(&:capitalize).join('')
      result = QbIif::DSL.const_get(class_name).new.build(&block)

      @output[method_name] ||= { headers: [], rows: [] }
      @output[method_name][:headers].concat(result[:headers])
      @output[method_name][:rows].concat(result[:rows])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qb_iif-0.1.0 lib/qb_iif/iif.rb