Class: Ods::Sheet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Sheet

Returns a new instance of Sheet.



97
98
99
# File 'lib/ods.rb', line 97

def initialize(content)
  @content = content
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



96
97
98
# File 'lib/ods.rb', line 96

def content
  @content
end

Instance Method Details

#[](row, col) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ods.rb', line 109

def [](row, col)
  (row - rows.length).times do
    rows.push(Row.new(@content.add_element('table:table-row',
                                           'table:style-name' => 'ro1'), rows.length+1))
  end
  row = rows[row-1]
  col = ('A'..col.to_s).to_a.index(col.to_s)
  cols = row.cols
  (col - cols.length + 1).times do
    no = (cols.last) ? cols.last.no.to_s.succ : 'A'
    cols.push(Cell.new(row.add_element('table:table-cell', 'office:value-type' => 'string'), no))
  end
  cols[col]
end

#columnObject



133
134
135
# File 'lib/ods.rb', line 133

def column
  Column.new(@content.xpath('table:table-column').first)
end

#nameObject



101
102
103
# File 'lib/ods.rb', line 101

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

#name=(name) ⇒ Object



105
106
107
# File 'lib/ods.rb', line 105

def name=(name)
  @content.set_attribute('table:name', name)
end

#rowsObject



124
125
126
127
128
129
130
131
# File 'lib/ods.rb', line 124

def rows
  return @rows if @rows
  @rows = []
  @content.xpath('./table:table-row').each_with_index{|row, index|
    @rows << Row.new(row, index+1)
  }
  @rows
end