Class: Report::Head

Inherits:
Object
  • Object
show all
Defined in:
lib/report/head.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ Head

Returns a new instance of Head.



4
5
6
7
# File 'lib/report/head.rb', line 4

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

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



3
4
5
# File 'lib/report/head.rb', line 3

def table
  @table
end

Instance Method Details

#each(report) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/report/head.rb', line 11

def each(report)
  @rows.each do |row|
    actual = row.map do |cell|
      case cell
      when String
        cell
      when Symbol
        unless report.respond_to?(cell)
          raise "#{report.inspect} doesn't respond to #{cell.inspect}"
        end
        report.send cell
      else
        raise "must pass String or Symbol to head row"
      end
    end
    yield actual
  end
end

#row(*cells) ⇒ Object



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

def row(*cells)
  @rows << cells
end