class ODFWriter::Table
Table: poulate and grow tables
Attributes
collection[RW]
name[RW]
proc[RW]
Public Class Methods
new(options)
click to toggle source
initialize
# File lib/odf_writer/table.rb, line 40 def initialize(options) @name = options[:name] @field = options[:field] @collection = options[:collection] @proc = options[:proc] @key = @field || @name @fields = [] @texts = [] @tables = [] @images = [] @bookmarks = [] @template_rows = [] @header = options[:header] || false @skip_if_empty = options[:skip_if_empty] || false end
Public Instance Methods
replace!(doc, manifest, file, row = nil)
click to toggle source
replace!
# File lib/odf_writer/table.rb, line 64 def replace!(doc, manifest, file, row = nil) return unless table = find_table_node(doc) @template_rows = table.xpath("table:table-row") @header = table.xpath("table:table-header-rows").empty? ? @header : false @collection = items(row, @key, @proc) if row if @skip_if_empty && @collection.empty? table.remove return end @collection.each do |item| new_node = get_next_row # # experimental: new node must be added to doc prior to replace! # else new_section does not have a name space # table.add_child(new_node) @tables.each { |t| t.replace!(new_node, manifest, file, item) } @texts.each { |t| t.replace!(new_node, item) } @fields.each { |f| f.replace!(new_node, item) } @images.each { |f| f.replace!(new_node, manifest, file, item) } end Image.unique_image_names( doc) if @images.present? @template_rows.each_with_index do |r, i| r.remove if (get_start_node..template_length) === i end end
Private Instance Methods
find_table_node(doc)
click to toggle source
# File lib/odf_writer/table.rb, line 129 def find_table_node(doc) tables = doc.xpath(".//table:table[@table:name='#{@name}']") tables.empty? ? nil : tables.first end
get_next_row()
click to toggle source
private
# File lib/odf_writer/table.rb, line 109 def get_next_row @row_cursor = get_start_node unless defined?(@row_cursor) ret = @template_rows[@row_cursor] if @template_rows.size == @row_cursor + 1 @row_cursor = get_start_node else @row_cursor += 1 end return ret.dup end
get_start_node()
click to toggle source
# File lib/odf_writer/table.rb, line 121 def get_start_node @header ? 1 : 0 end
template_length()
click to toggle source
# File lib/odf_writer/table.rb, line 125 def template_length @tl ||= @template_rows.size end