Class: ODFReport::Table
- Inherits:
-
Object
- Object
- ODFReport::Table
- Defined in:
- lib/odf-report/table.rb
Constant Summary
Constants included from HashGsub
Instance Attribute Summary collapse
-
#collection_field ⇒ Object
Returns the value of attribute collection_field.
-
#data ⇒ Object
Returns the value of attribute data.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#header ⇒ Object
Returns the value of attribute header.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#rows ⇒ Object
Returns the value of attribute rows.
Instance Method Summary collapse
- #add_column(name, field = nil, &block) ⇒ Object
-
#initialize(opts) ⇒ Table
constructor
A new instance of Table.
- #populate!(row) ⇒ Object
- #replace!(doc, row = nil) ⇒ Object
Methods included from HashGsub
#hash_gsub!, #html_escape, #node_hash_gsub!, #odf_linebreak
Methods included from Nested
#get_collection_from_item, #get_fields_with_values, #replace_values!
Constructor Details
#initialize(opts) ⇒ Table
Returns a new instance of Table.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/odf-report/table.rb', line 8 def initialize(opts) @name = opts[:name] @collection_field = opts[:collection_field] @collection = opts[:collection] @parent = opts[:parent] @fields = {} @template_rows = [] @header = opts[:header] || false end |
Instance Attribute Details
#collection_field ⇒ Object
Returns the value of attribute collection_field.
6 7 8 |
# File 'lib/odf-report/table.rb', line 6 def collection_field @collection_field end |
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/odf-report/table.rb', line 6 def data @data end |
#fields ⇒ Object
Returns the value of attribute fields.
6 7 8 |
# File 'lib/odf-report/table.rb', line 6 def fields @fields end |
#header ⇒ Object
Returns the value of attribute header.
6 7 8 |
# File 'lib/odf-report/table.rb', line 6 def header @header end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/odf-report/table.rb', line 6 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
6 7 8 |
# File 'lib/odf-report/table.rb', line 6 def parent @parent end |
#rows ⇒ Object
Returns the value of attribute rows.
6 7 8 |
# File 'lib/odf-report/table.rb', line 6 def rows @rows end |
Instance Method Details
#add_column(name, field = nil, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/odf-report/table.rb', line 20 def add_column(name, field=nil, &block) if field @fields[name] = lambda { |item| item.send(field)} elsif block_given? @fields[name] = block else @fields[name] = lambda { |item| item.send(name)} end end |
#populate!(row) ⇒ Object
30 31 32 |
# File 'lib/odf-report/table.rb', line 30 def populate!(row) @collection = get_collection_from_item(row, @collection_field) if row end |
#replace!(doc, row = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/odf-report/table.rb', line 34 def replace!(doc, row = nil) return unless table = find_table_node(doc) populate!(row) @template_rows = table.xpath("table:table-row") @collection.each do |data_item| new_node = get_next_row replace_values!(new_node, data_item) table.add_child(new_node) end @template_rows.each_with_index do |r, i| r.remove if (get_start_node..template_length) === i end end |