Sha256: ca9b820416fe5b486f79dfd4715319c8e83c6312c4062131c055cd241b7a8ed3

Contents?: true

Size: 935 Bytes

Versions: 4

Compression:

Stored size: 935 Bytes

Contents

module Riif::DSL
  class Base

    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 = :class if method_name == :klass
      method_name = "1099".to_sym if method_name == :_1099

      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

4 entries across 4 versions & 1 rubygems

Version Path
riif-1.0.0 lib/riif/dsl/base.rb
riif-0.9.0 lib/riif/dsl/base.rb
riif-0.8.0 lib/riif/dsl/base.rb
riif-0.7.0 lib/riif/dsl/base.rb