Class: Tabloid::Group
- Inherits:
-
Object
- Object
- Tabloid::Group
- Defined in:
- lib/tabloid/group.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
-
#initialize(options) ⇒ Group
constructor
A new instance of Group.
- #summarize(key, &block) ⇒ Object
- #to_csv ⇒ Object
- #to_html ⇒ Object
- #total_required? ⇒ Boolean
Constructor Details
#initialize(options) ⇒ Group
Returns a new instance of Group.
7 8 9 10 11 12 13 14 |
# File 'lib/tabloid/group.rb', line 7 def initialize() @rows = [:rows] @columns = [:columns] @visible_column_count = @columns.select { |col| !col.hidden? }.count @total_required = [:total] @label = [:label] raise ArgumentError.new("Must supply row data to a Group") unless @rows end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/tabloid/group.rb', line 4 def columns @columns end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
5 6 7 |
# File 'lib/tabloid/group.rb', line 5 def label @label end |
#rows ⇒ Object (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_csv ⇒ Object
33 34 35 |
# File 'lib/tabloid/group.rb', line 33 def to_csv header_row_csv + rows.map(&:to_csv).join end |
#to_html ⇒ Object
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
16 17 18 |
# File 'lib/tabloid/group.rb', line 16 def total_required? !(@total_required.nil? || @total_required == false) end |