Class: Row
Overview
Objects of this class represent rows in a spreadsheet table
Constant Summary collapse
- @@DEF_HEIGHT =
2
- @@log =
self.init_logger(STDOUT)
Instance Attribute Summary collapse
-
#cells ⇒ Object
readonly
Returns the value of attribute cells.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
- #add(cell) ⇒ Object (also: #<<)
- #each(&b) ⇒ Object
-
#initialize(number = nil) ⇒ Row
constructor
A new instance of Row.
- #resize ⇒ Object
- #to_s ⇒ Object
Methods included from Logging
init_logger, log_level=, log_target=
Methods included from File_Checking
Constructor Details
#initialize(number = nil) ⇒ Row
Returns a new instance of Row.
32 33 34 35 36 37 |
# File 'lib/row.rb', line 32 def initialize(number = nil) @log = @@log @number = number @cells = Array.new @height = 1 end |
Instance Attribute Details
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
77 78 79 |
# File 'lib/row.rb', line 77 def cells @cells end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
77 78 79 |
# File 'lib/row.rb', line 77 def height @height end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
77 78 79 |
# File 'lib/row.rb', line 77 def number @number end |
Instance Method Details
#add(cell) ⇒ Object Also known as: <<
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/row.rb', line 39 def add(cell) n_cell = nil if cell.respond_to?(:to_cell) n_cell = cell elsif cell.respond_to?(:to_i) n_cell = Cell.new(@number, cell) else msg = 'For a new cell, a colum-number must be specified' @log.error(red(msg)) raise StandardError(msg) end @cells.insert(n_cell.col, n_cell) @cells.compact! resize() end |
#each(&b) ⇒ Object
55 56 57 58 59 |
# File 'lib/row.rb', line 55 def each(&b) @cells.each do |c| yield(c) end end |
#resize ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/row.rb', line 61 def resize() if(@cells && ! @cells.empty? ) if(@cells.length == 1 ) @ideal_height = @cells[0].ideal_height else @ideal_height = @cells.max{|c1, c2| c1.ideal_height <=> c2.ideal_height}.ideal_height end @height = @ideal_height end @height ||= @@DEF_HEIGHT end |
#to_s ⇒ Object
73 74 75 |
# File 'lib/row.rb', line 73 def to_s '#<' << self.class.name << ':' << object_id.to_s << "{number=%s height=%s cells.length=%s}" %[@number.to_s, @height.to_s, @cells.length.to_s] end |