Class: Rspreadsheet::RowWithXMLNode
Instance Attribute Summary collapse
-
#xmlnode ⇒ Object
Returns the value of attribute xmlnode.
Instance Method Summary collapse
- #add_cell(repeated = 1) ⇒ Object
- #cellnodes(coli) ⇒ Object
- #cells(coli) ⇒ Object
- #first_unused_column_index ⇒ Object
- #nonemptycells ⇒ Object
- #nonemptycellsindexes ⇒ Object
- #style_name=(value) ⇒ Object
- #used_col_range ⇒ Object
- #used_range ⇒ Object
Methods inherited from Row
Instance Attribute Details
#xmlnode ⇒ Object
Returns the value of attribute xmlnode.
125 126 127 |
# File 'lib/rspreadsheet/row.rb', line 125 def xmlnode @xmlnode end |
Instance Method Details
#add_cell(repeated = 1) ⇒ Object
160 161 162 163 164 165 |
# File 'lib/rspreadsheet/row.rb', line 160 def add_cell(repeated=1) cell = Cell.new(self,first_unused_column_index) Tools.set_ns_attribute(cell.xmlnode,'table','number-columns-repeated',repeated) if repeated>1 @xmlnode << cell.xmlnode cell end |
#cellnodes(coli) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/rspreadsheet/row.rb', line 145 def cellnodes(coli) cellnode = nil while true curr_coli=1 cellnode = @xmlnode.elements.select{|n| n.name=='table-cell'}.find do |el| curr_coli += (Tools.get_ns_attribute_value(el, 'table', 'number-columns-repeated') || 1).to_i curr_coli > coli end unless cellnode.nil? return cellnode else add_cell end end end |
#cells(coli) ⇒ Object
127 128 129 130 131 |
# File 'lib/rspreadsheet/row.rb', line 127 def cells(coli) coli = coli.to_i return nil if coli.to_i<=0 Cell.new(self,coli,cellnodes(coli)) end |
#first_unused_column_index ⇒ Object
170 171 172 173 174 |
# File 'lib/rspreadsheet/row.rb', line 170 def first_unused_column_index 1 + @xmlnode.elements.select{|n| n.name=='table-cell'}.reduce(0) do |sum, el| sum + (Tools.get_ns_attribute_value(el, 'table', 'number-columns-repeated') || 1).to_i end end |
#nonemptycells ⇒ Object
132 133 134 |
# File 'lib/rspreadsheet/row.rb', line 132 def nonemptycells nonemptycellsindexes.collect{ |index| cells(index) } end |
#nonemptycellsindexes ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/rspreadsheet/row.rb', line 135 def nonemptycellsindexes used_col_range.to_a.select do |coli| cellnode = cellnodes(coli) !(cellnode.content.nil? or cellnode.content.empty? or cellnode.content =='') or !cellnode.attributes.to_a.reject{ |attr| attr.name == 'number-columns-repeated'}.empty? end end |
#style_name=(value) ⇒ Object
126 |
# File 'lib/rspreadsheet/row.rb', line 126 def style_name=(value); Tools.set_ns_attribute(@xmlnode,'table','style-name',value) end |
#used_col_range ⇒ Object
142 143 144 |
# File 'lib/rspreadsheet/row.rb', line 142 def used_col_range 1..first_unused_column_index-1 end |
#used_range ⇒ Object
166 167 168 169 |
# File 'lib/rspreadsheet/row.rb', line 166 def used_range fu = first_unused_column_index (fu>1) ? 1..fu : nil end |