Class: Column
Overview
Objects of this class represent columns in a spreadsheet table
Constant Summary collapse
- @@DEF_WIDTH =
15- @@col_width =
@@DEF_WIDTH- @@columns =
Array.new
Constants included from BasicLogging
BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Attributes included from BasicLogging
Class Method Summary collapse
Instance Method Summary collapse
- #add(cell) ⇒ Object (also: #<<)
- #each(&b) ⇒ Object
-
#initialize(number = nil) ⇒ Column
constructor
A new instance of Column.
- #resize(width) ⇒ Object
- #to_s ⇒ Object
Methods included from BasicLogging
is_muted?, #log, mute, #set_level, set_level, set_target, #set_target
Constructor Details
#initialize(number = nil) ⇒ Column
Returns a new instance of Column.
28 29 30 31 32 33 |
# File 'lib/column.rb', line 28 def initialize(number = nil) @number = number @cells = Array.new @width = @@col_width @@columns << self end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
78 79 80 |
# File 'lib/column.rb', line 78 def number @number end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
78 79 80 |
# File 'lib/column.rb', line 78 def width @width end |
Class Method Details
.col_width ⇒ Object
57 58 59 |
# File 'lib/column.rb', line 57 def self::col_width @@col_width end |
.col_width=(w) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/column.rb', line 61 def self::col_width=(w) @@col_width = w debug(@number.to_s << ' ' <<"self::col_width=(#{w}), calling resize") @@columns.each {|col| col.resize(w)} end |
Instance Method Details
#add(cell) ⇒ Object Also known as: <<
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/column.rb', line 35 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( cell, @number) else msg = 'For a new cell, a row-number must be specified' error(yellow(msg)) raise StandardError(msg) end @cells.insert(n_cell.row, n_cell) @cells.compact! set_limits end |
#each(&b) ⇒ Object
51 52 53 54 55 |
# File 'lib/column.rb', line 51 def each(&b) @cells.each do |c| yield(c) end end |
#resize(width) ⇒ Object
68 69 70 71 72 |
# File 'lib/column.rb', line 68 def resize(width) @width = width debug(@number.to_s << ' ' <<'calling resize') @cells.each {|cell| cell.resize} end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/column.rb', line 74 def to_s '<' << self.class.name.dup << ':' << object_id.to_s << "{number=%s width=%s cells.length=}>" %[@number, @cells.length] end |