Class: Report::Body

Inherits:
Object
  • Object
show all
Defined in:
lib/report/body.rb,
lib/report/body/row.rb,
lib/report/body/column.rb

Defined Under Namespace

Classes: Column, Row

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ Body

Returns a new instance of Body.



10
11
12
13
# File 'lib/report/body.rb', line 10

def initialize(table)
  @table = table
  @columns = []
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



7
8
9
# File 'lib/report/body.rb', line 7

def columns
  @columns
end

#method_argsObject (readonly)

Returns the value of attribute method_args.



9
10
11
# File 'lib/report/body.rb', line 9

def method_args
  @method_args
end

#method_idObject (readonly)

Returns the value of attribute method_id.



8
9
10
# File 'lib/report/body.rb', line 8

def method_id
  @method_id
end

#tableObject (readonly)

Returns the value of attribute table.



6
7
8
# File 'lib/report/body.rb', line 6

def table
  @table
end

Instance Method Details

#column(*args, &blk) ⇒ Object



20
21
22
# File 'lib/report/body.rb', line 20

def column(*args, &blk)
  @columns << Column.new(*([self]+args), &blk)
end

#each(report) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/report/body.rb', line 23

def each(report)
  block_taken = false
  if method_args
    enum = report.send(method_id, *method_args) do |obj|
      block_taken = true
      yield Row.new(self, report, obj)
    end
  else
    enum = report.send(method_id) do |obj|
      block_taken = true
      yield Row.new(self, report, obj)
    end
  end
  unless block_taken
    enum.each do |obj|
      yield Row.new(self, report, obj)
    end
  end
end

#rows(*args) ⇒ Object



14
15
16
17
18
19
# File 'lib/report/body.rb', line 14

def rows(*args)
  @method_id = args.shift
  if args.last.is_a?(Array)
    @method_args = args.last
  end
end