Class: TableFu::Row
- Inherits:
-
Array
- Object
- Array
- TableFu::Row
- Defined in:
- lib/table_fu.rb
Overview
TableFu::Row adds functionality to an row array in a TableFu instance
Instance Attribute Summary
- - (Object) row_num readonly Returns the value of attribute row_num.
Instance Method Summary
- - (Object) <=>(b) Comparator for sorting a spreadsheet row.
- - (Object) columns
- - (Object) datum_for(col_name) (also: #column_for) This returns a Datum object for a header name.
- - (Row) initialize(row, row_num, spreadsheet) constructor A new instance of Row.
Constructor Details
- (Row) initialize(row, row_num, spreadsheet)
A new instance of Row
181 182 183 184 185 |
# File 'lib/table_fu.rb', line 181 def initialize(row, row_num, spreadsheet) self.replace row @row_num = row_num @spreadsheet = spreadsheet end |
Instance Attribute Details
- (Object) row_num (readonly)
Returns the value of attribute row_num
179 180 181 |
# File 'lib/table_fu.rb', line 179 def row_num @row_num end |
Instance Method Details
- (Object) <=>(b)
Comparator for sorting a spreadsheet row.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/table_fu.rb', line 215 def <=>(b) if @spreadsheet.sorted_by column = @spreadsheet.sorted_by.keys.first order = @spreadsheet.sorted_by[@spreadsheet.sorted_by.keys.first]["order"] format = @spreadsheet.sorted_by[@spreadsheet.sorted_by.keys.first]["format"] a = column_for(column).value || '' b = b.column_for(column).value || '' if format a = TableFu::Formatting.send(format, a) || '' b = TableFu::Formatting.send(format, b) || '' end result = a <=> b result = -1 if result.nil? result = result * -1 if order == 'descending' result else -1 end end |
- (Object) columns
187 188 189 190 191 192 193 |
# File 'lib/table_fu.rb', line 187 def columns all_cols = [] @spreadsheet.columns.each do |column| all_cols << datum_for(column) end all_cols end |
- (Object) datum_for(col_name) Also known as: column_for
This returns a Datum object for a header name. Will return a nil Datum object for nonexistant column names
Parameters: header name
Returns: Datum object
204 205 206 207 208 209 210 |
# File 'lib/table_fu.rb', line 204 def datum_for(col_name) if col_num = @spreadsheet.column_headers.index(col_name) TableFu::Datum.new(self[col_num], col_name, @row_num, @spreadsheet) else # Return a nil Datum object for non existant column names TableFu::Datum.new(nil, col_name, @row_num, @spreadsheet) end end |