Sha256: d6f47cc3e13d483db0481ec8fc50babcc13589415ef529f59ff08e4e0bfb154b

Contents?: true

Size: 894 Bytes

Versions: 3

Compression:

Stored size: 894 Bytes

Contents

module QbIif::DSL
  class Base

    include QbIif::Keywords

    def initialize
      @rows = []
      @current_row = []
    end

    def build(&block)

      instance_eval(&block)

      output
    end

    def row(&block)
      @current_row = [self.class::START_COLUMN]

      instance_eval(&block)

      @rows << @current_row
    end

    def output
      {
        headers: headers,
        rows: rows
      }
    end

    def headers
      [
        ["!#{self.class::START_COLUMN}"].concat(
          self.class::HEADER_COLUMNS.map(&:upcase)
        )
      ]
    end

    def rows
      @rows
    end

    def method_missing(method_name, *args, &block)
      method_name = escaped(method_name)
      if self.class::HEADER_COLUMNS.include?(method_name)
        @current_row[self.class::HEADER_COLUMNS.index(method_name) + 1] = args[0]
      else
        super
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
qb_iif-0.1.2 lib/qb_iif/dsl/base.rb
qb_iif-0.1.1 lib/qb_iif/dsl/base.rb
qb_iif-0.1.0 lib/qb_iif/dsl/base.rb