Class: Riif::DSL::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/riif/dsl/base.rb

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



4
5
6
7
# File 'lib/riif/dsl/base.rb', line 4

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/riif/dsl/base.rb', line 43

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

Instance Method Details

#build(&block) ⇒ Object



9
10
11
12
13
14
# File 'lib/riif/dsl/base.rb', line 9

def build(&block)

  instance_eval(&block)

  output
end

#headersObject



31
32
33
34
35
36
37
# File 'lib/riif/dsl/base.rb', line 31

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

#outputObject



24
25
26
27
28
29
# File 'lib/riif/dsl/base.rb', line 24

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

#row(&block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/riif/dsl/base.rb', line 16

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

  instance_eval(&block)

  @rows << @current_row
end

#rowsObject



39
40
41
# File 'lib/riif/dsl/base.rb', line 39

def rows
  @rows
end