Class: Tabloid::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/tabloid/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Group

Returns a new instance of Group.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
# File 'lib/tabloid/group.rb', line 7

def initialize(options)
  @rows                 = options[:rows]
  @columns              = options[:columns]
  @visible_column_count = @columns.select { |col| !col.hidden? }.count
  @total_required       = options[:total]
  @label                = options[:label]
  raise ArgumentError.new("Must supply row data to a Group") unless @rows
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



4
5
6
# File 'lib/tabloid/group.rb', line 4

def columns
  @columns
end

#labelObject (readonly)

Returns the value of attribute label.



5
6
7
# File 'lib/tabloid/group.rb', line 5

def label
  @label
end

#rowsObject (readonly)

Returns the value of attribute rows.



3
4
5
# File 'lib/tabloid/group.rb', line 3

def rows
  @rows
end

Instance Method Details

#summarize(key, &block) ⇒ Object



29
30
31
# File 'lib/tabloid/group.rb', line 29

def summarize(key, &block)
  @rows[1..-1].inject(@rows[0].send(key)){|summary, row| block.call(summary, row.send(key))  }
end

#to_csvObject



33
34
35
# File 'lib/tabloid/group.rb', line 33

def to_csv
  header_row_csv + rows.map(&:to_csv).join
end

#to_htmlObject



37
38
39
# File 'lib/tabloid/group.rb', line 37

def to_html
  header_row_html + rows.map(&:to_html).join
end

#total_required?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/tabloid/group.rb', line 16

def total_required?
  !(@total_required.nil? || @total_required == false)
end