Class: NattyUI::TableRenderer::Cell

Inherits:
Object
  • Object
show all
Defined in:
lib/natty-ui/table_renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cell, width) ⇒ Cell

Returns a new instance of Cell.



111
112
113
114
115
116
117
118
119
# File 'lib/natty-ui/table_renderer.rb', line 111

def initialize(cell, width)
  return @text = [] unless cell
  att = cell.attributes
  @padding = att.padding.dup
  @align = att.align
  @vertical = att.vertical
  @style = att.style_bbcode
  @text = width_corrected(cell.text, width)
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



94
95
96
# File 'lib/natty-ui/table_renderer.rb', line 94

def text
  @text
end

#widthObject (readonly)

Returns the value of attribute width.



94
95
96
# File 'lib/natty-ui/table_renderer.rb', line 94

def width
  @width
end

Instance Method Details

#correct_height(height) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/natty-ui/table_renderer.rb', line 96

def correct_height(height)
  return self if (diff = height - @text.size) <= 0
  @text =
    case @vertical
    when :bottom
      [Array.new(diff, @empty), @text]
    when :middle
      tc = diff / 2
      [Array.new(tc, @empty), @text, Array.new(diff - tc, @empty)]
    else
      [@text, Array.new(diff, @empty)]
    end.flatten(1)
  self
end