Class: Row
Overview
Objects of this class represent rows in a spreadsheet table
Constant Summary collapse
- @@DEF_HEIGHT =
2
Constants included from BasicLogging
BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN
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.
Attributes included from BasicLogging
Instance Method Summary collapse
-
#add(cell) ⇒ Object
(also: #<<)
add a cell to the row.
-
#each(&b) ⇒ Object
execute block on each cell in the row.
-
#initialize(number = nil) ⇒ Row
constructor
A new instance of Row.
-
#resize ⇒ Object
adapt the height of the row to the ideal height of the highest cell.
-
#to_s ⇒ Object
returns a string representation of the row.
Methods included from BasicLogging
is_muted?, #log, mute, #set_level, set_level, set_target, #set_target
Constructor Details
#initialize(number = nil) ⇒ Row
Returns a new instance of Row.
25 26 27 28 29 |
# File 'lib/row.rb', line 25 def initialize(number = nil) @number = number @cells = Array.new @height = 1 end |
Instance Attribute Details
#cells ⇒ Object (readonly)
Returns the value of attribute cells.
74 75 76 |
# File 'lib/row.rb', line 74 def cells @cells end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
74 75 76 |
# File 'lib/row.rb', line 74 def height @height end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
74 75 76 |
# File 'lib/row.rb', line 74 def number @number end |
Instance Method Details
#add(cell) ⇒ Object Also known as: <<
add a cell to the row
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/row.rb', line 32 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' error(red(msg)) raise StandardError(msg) end @cells.insert(n_cell.col, n_cell) @cells.compact! resize() end |
#each(&b) ⇒ Object
execute block on each cell in the row
49 50 51 52 53 |
# File 'lib/row.rb', line 49 def each(&b) @cells.each do |c| yield(c) end end |
#resize ⇒ Object
adapt the height of the row to the ideal height of the highest cell
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/row.rb', line 57 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
returns a string representation of the row
70 71 72 |
# File 'lib/row.rb', line 70 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 |