Class: Ods::Sheet
- Inherits:
-
Object
- Object
- Ods::Sheet
- Defined in:
- lib/ods/sheet.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Instance Method Summary collapse
-
#[](row_index, col_index) ⇒ Object
access by (0,0) = top left.
- #csv ⇒ Object
-
#initialize(content) ⇒ Sheet
constructor
A new instance of Sheet.
- #name ⇒ Object
- #rows ⇒ Object
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
#content ⇒ Object (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 |
#csv ⇒ Object
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 |
#name ⇒ Object
9 10 11 |
# File 'lib/ods/sheet.rb', line 9 def name content.attribute('name').to_s end |
#rows ⇒ Object
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 |