Class: Ods::Sheet

Inherits:
Object
  • Object
show all
Defined in:
lib/ods/sheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Sheet

Returns a new instance of Sheet.



5
6
7
# File 'lib/ods/sheet.rb', line 5

def initialize(content)
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



3
4
5
# File 'lib/ods/sheet.rb', line 3

def content
  @content
end

Instance Method Details

#[](row_index, col_index) ⇒ Object

access by (0,0) = top left



14
15
16
17
18
19
20
21
# File 'lib/ods/sheet.rb', line 14

def [](row_index, col_index)
  row = rows[row_index]
  if row.kind_of?(Array)
    puts "bad #{row_index} #{col_index}"
    #puts row
  end
  row.nil? ? nil : row.cols[col_index]
end

#csvObject



36
37
38
39
40
41
42
# File 'lib/ods/sheet.rb', line 36

def csv
  CSV do |csv|
    rows.each do |row|
      csv << row.cols.map(&:value)
    end
  end
end

#nameObject



9
10
11
# File 'lib/ods/sheet.rb', line 9

def name
  content.attribute('name').to_s
end

#rowsObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ods/sheet.rb', line 23

def rows
  return @rows if @rows
  @rows = []
  content.xpath('descendant::table:table-row').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