class Ods::Sheet

Attributes

content[R]

Public Class Methods

new(content) click to toggle source
# File lib/ods/sheet.rb, line 5
def initialize(content)
  @content = content
end

Public Instance Methods

[](row_index, col_index) click to toggle source

access by (0,0) = top left

# File lib/ods/sheet.rb, line 14
def [](row_index, col_index)
  row = data[row_index]
  row && row[col_index]
end
csv() click to toggle source
# File lib/ods/sheet.rb, line 43
def csv
  CSV do |csv|
    data.each { |row| csv << row }
  end
end
data() click to toggle source
# File lib/ods/sheet.rb, line 39
def data
  @data ||= rows.map(&:data)
end
name() click to toggle source
# File lib/ods/sheet.rb, line 9
def name
  content.attribute('name').to_s
end
rows() click to toggle source
# File lib/ods/sheet.rb, line 19
def rows
  return @rows if @rows
  @rows = []
  src_rows = content.xpath('descendant::table:table-row')

  # ignore trailing empty rows
  while (last_row = src_rows.last) && (Row.new(last_row, self).data.length == 0)
    src_rows.pop
  end

  src_rows.each do |node|
    a_row = Row.new(node, self)
    repeat = node['table:number-rows-repeated'] || 1
    repeat.to_i.times do
      @rows << a_row
    end
  end
  @rows
end