Sha256: 9033f7a12db3dc641206a309b17827a7ff373e5e3a3fdeac86465222fd28555b

Contents?: true

Size: 823 Bytes

Versions: 8

Compression:

Stored size: 823 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)
      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

8 entries across 8 versions & 2 rubygems

Version Path
iif-0.6.1 lib/riif/dsl/base.rb
riif-0.6.0 lib/riif/dsl/base.rb
riif-0.5.0 lib/riif/dsl/base.rb
riif-0.4.0 lib/riif/dsl/base.rb
riif-0.3.0 lib/riif/dsl/base.rb
riif-0.2.0 lib/riif/dsl/base.rb
riif-0.1.0 lib/riif/dsl/base.rb
riif-0.0.1 lib/riif/dsl/base.rb