Class | Spreadsheet::Row |
In: |
lib/spreadsheet/row.rb
|
Parent: | Array |
The Row class. Encapsulates Cell data and formatting. Since Row is a subclass of Array, you may use all the standard Array methods to manipulate a Row. By convention, Row#at will give you raw values, while Row#[] may be overridden to return enriched data if necessary (see also the Date- and DateTime-handling in Excel::Row#[]
Useful Attributes are:
idx: | The 0-based index of this Row in its Worksheet. |
formats: | A parallel array containing Formatting information for all cells stored in a Row. |
default_format: | The default Format used when writing a Cell if no explicit Format is stored in formats for the cell. |
height: | The height of this Row in points (defaults to 12). |
default_format | [R] | |
formats | [R] | |
height | [RW] | |
idx | [RW] | |
worksheet | [RW] |
# File lib/spreadsheet/row.rb, line 22 22: def format_updater *keys 23: keys.each do |key| 24: unless instance_methods.include? "unupdated_#{key}=" 25: alias_method "unupdated_#{key}=""unupdated_#{key}=", "#{key}=""#{key}=" 26: define_method "#{key}=" do |value| 27: send "unupdated_#{key}=", value 28: @worksheet.row_updated @idx, self if @worksheet 29: value 30: end 31: end 32: end 33: end
# File lib/spreadsheet/row.rb, line 60 60: def initialize worksheet, idx, cells=[] 61: @default_format = nil 62: @worksheet = worksheet 63: @idx = idx 64: super cells 65: @formats = [] 66: @height = 12.1 67: end
# File lib/spreadsheet/row.rb, line 34 34: def updater *keys 35: keys.each do |key| 36: ## Passing blocks to methods defined with define_method is not possible 37: # in Ruby 1.8: 38: # http://groups.google.com/group/ruby-talk-google/msg/778184912b769e5f 39: # use class_eval as suggested by someone else in 40: # http://rubyforge.org/tracker/index.php?func=detail&aid=25732&group_id=678&atid=2677 41: class_eval "def \#{key}(*args)\nres = super(*args)\n@worksheet.row_updated @idx, self if @worksheet\nres\nend\n", __FILE__, __LINE__ 42: end 43: end
first_used the 0-based index of the first non-blank Cell.
# File lib/spreadsheet/row.rb, line 78 78: def first_used 79: [ index_of_first(self), index_of_first(@formats) ].compact.min 80: end
The Format for the Cell at idx (0-based), or the first valid Format in Row#default_format, Column#default_format and Worksheet#default_format.
# File lib/spreadsheet/row.rb, line 84 84: def format idx 85: @formats[idx] || @default_format \ 86: || @worksheet.column(idx).default_format if @worksheet 87: end
Returns a copy of self with nil-values appended for empty cells that have an associated Format. This is primarily a helper-function for the writer classes.
# File lib/spreadsheet/row.rb, line 92 92: def formatted 93: copy = dup 94: @formats.rcompact! 95: if copy.length < @formats.size 96: copy.concat Array.new(@formats.size - copy.length) 97: end 98: copy 99: end
# File lib/spreadsheet/row.rb, line 112 112: def inspect 113: variables = instance_variables.collect do |name| 114: "%s=%s" % [name, instance_variable_get(name)] 115: end.join(' ') 116: sprintf "#<%s:0x%014x %s %s>", self.class, object_id, variables, super 117: end