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.



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

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



53
54
55
56
57
58
59
60
61
62
# File 'lib/riif/dsl/base.rb', line 53

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



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/riif/dsl/base.rb', line 8

def build(&block)
  if block_given?
    if block.arity == 1
      yield(self)
    else
      instance_eval(&block)
    end
  end

  output
end

#headersObject



41
42
43
44
45
46
47
# File 'lib/riif/dsl/base.rb', line 41

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

#outputObject



34
35
36
37
38
39
# File 'lib/riif/dsl/base.rb', line 34

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

#row(&block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/riif/dsl/base.rb', line 20

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

  if block_given?
    if block.arity == 1
      yield(self)
    else
      instance_eval(&block)
    end
  end

  @rows << @current_row
end

#rowsObject



49
50
51
# File 'lib/riif/dsl/base.rb', line 49

def rows
  @rows
end