Class: Row

Inherits:
Object
  • Object
show all
Includes:
BasicLogging
Defined in:
lib/row.rb

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

Attributes included from BasicLogging

#log_level, #target

Instance Method Summary collapse

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

#cellsObject (readonly)

Returns the value of attribute cells.



69
70
71
# File 'lib/row.rb', line 69

def cells
  @cells
end

#heightObject (readonly)

Returns the value of attribute height.



69
70
71
# File 'lib/row.rb', line 69

def height
  @height
end

#numberObject (readonly)

Returns the value of attribute number.



69
70
71
# File 'lib/row.rb', line 69

def number
  @number
end

Instance Method Details

#add(cell) ⇒ Object Also known as: <<



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/row.rb', line 31

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



47
48
49
50
51
# File 'lib/row.rb', line 47

def each(&b)
  @cells.each do |c|
    yield(c) 
  end
end

#resizeObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/row.rb', line 53

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_sObject



65
66
67
# File 'lib/row.rb', line 65

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