Class: Xport::ExportBuilder
- Inherits:
-
Object
- Object
- Xport::ExportBuilder
- Defined in:
- lib/xport/export_builder.rb
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#export ⇒ Object
readonly
Returns the value of attribute export.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#styles ⇒ Object
readonly
Returns the value of attribute styles.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
-
#widths ⇒ Object
readonly
Returns the value of attribute widths.
Instance Method Summary collapse
- #column(name, type: nil, style: nil, width: nil, header: nil, group: nil, &block) ⇒ Object
- #grouped? ⇒ Boolean
- #groups_with_offset_and_colspan ⇒ Object
-
#initialize(export, &block) ⇒ ExportBuilder
constructor
A new instance of ExportBuilder.
Constructor Details
#initialize(export, &block) ⇒ ExportBuilder
Returns a new instance of ExportBuilder.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/xport/export_builder.rb', line 7 def initialize(export, &block) @export = export @columns = [] @headers = [] @groups = [] @styles = [] @types = [] @widths = [] @blocks = [] instance_exec(export, &block) end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
5 6 7 |
# File 'lib/xport/export_builder.rb', line 5 def blocks @blocks end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
5 6 7 |
# File 'lib/xport/export_builder.rb', line 5 def columns @columns end |
#export ⇒ Object (readonly)
Returns the value of attribute export.
5 6 7 |
# File 'lib/xport/export_builder.rb', line 5 def export @export end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
5 6 7 |
# File 'lib/xport/export_builder.rb', line 5 def groups @groups end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/xport/export_builder.rb', line 5 def headers @headers end |
#styles ⇒ Object (readonly)
Returns the value of attribute styles.
5 6 7 |
# File 'lib/xport/export_builder.rb', line 5 def styles @styles end |
#types ⇒ Object (readonly)
Returns the value of attribute types.
5 6 7 |
# File 'lib/xport/export_builder.rb', line 5 def types @types end |
#widths ⇒ Object (readonly)
Returns the value of attribute widths.
5 6 7 |
# File 'lib/xport/export_builder.rb', line 5 def widths @widths end |
Instance Method Details
#column(name, type: nil, style: nil, width: nil, header: nil, group: nil, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/xport/export_builder.rb', line 19 def column(name, type: nil, style: nil, width: nil, header: nil, group: nil, &block) columns << name headers << (header || name) groups << group types << type styles << style widths << width blocks << block end |
#grouped? ⇒ Boolean
29 30 31 |
# File 'lib/xport/export_builder.rb', line 29 def grouped? groups.any? end |
#groups_with_offset_and_colspan ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/xport/export_builder.rb', line 33 def groups_with_offset_and_colspan offset = 0 colspan = 1 [].tap do |result| groups.each do |group| last = result.last # check if current group is same as last group if last && last[0] == group # if group is the same, update colspan last[2] += 1 else result << [group, offset, colspan] end offset += 1 end end end |