Class: NattyUI::Table::Cell::Attributes
- Inherits:
-
Object
- Object
- NattyUI::Table::Cell::Attributes
- Defined in:
- lib/natty-ui/helper/table.rb
Overview
Formatting attributes for a NattyUI::Table::Cell, Row, or NattyUI::Table::Column.
An Attributes instance is exposed on each NattyUI::Table::Cell (via #attributes),
each Row (via Row#attributes), and each NattyUI::Table::Column (via
NattyUI::Table::Column#attributes). Attributes set on a row or column serve as
defaults that are merged with individual cell attributes during rendering.
Instance Attribute Summary collapse
-
#align ⇒ :left, ...
Horizontal text alignment within the cell.
-
#bottom_padding ⇒ Integer
Bottom padding in lines.
-
#eol ⇒ Boolean
Whether line breaks inside the text are collapsed to spaces.
-
#height ⇒ Integer, ...
Height constraint for this cell.
-
#max_height ⇒ Integer?
Maximum row height in lines for this cell.
-
#max_width ⇒ Integer, ...
Maximum column width in characters for this cell.
-
#min_height ⇒ Integer?
Minimum row height in lines for this cell.
-
#min_width ⇒ Integer, ...
Minimum column width in characters for this cell.
-
#padding ⇒ Array(Integer, Integer, Integer, Integer)
Cell padding as a four-element array
[top, right, bottom, left]. -
#padding_left ⇒ Integer
Left padding in characters.
-
#right_padding ⇒ Integer
Right padding in characters.
-
#spaces ⇒ Boolean
Whether whitespace are preserved.
-
#top_padding ⇒ Integer
Top padding in lines.
-
#vertical ⇒ :top, ...
Vertical text alignment within the cell.
-
#width ⇒ Integer, ...
Width constraint for this cell.
Instance Method Summary collapse
-
#assign(attributes) ⇒ Cell::Attributes
Applies attribute values from a hash.
-
#empty? ⇒ Boolean
Returns
truewhen all attributes are at their default values. -
#initialize(**attributes) ⇒ Attributes
constructor
A new instance of Attributes.
-
#left_padding ⇒ Integer
Left padding in characters.
Constructor Details
#initialize(**attributes) ⇒ Attributes
Returns a new instance of Attributes.
461 462 463 464 465 |
# File 'lib/natty-ui/helper/table.rb', line 461 def initialize(**attributes) @eol = @spaces = true @padding = [0, 0, 0, 0] assign(attributes) unless attributes.empty? end |
Instance Attribute Details
#align ⇒ :left, ...
Horizontal text alignment within the cell.
70 71 72 |
# File 'lib/natty-ui/helper/table.rb', line 70 def align @align end |
#bottom_padding ⇒ Integer
Bottom padding in lines.
368 |
# File 'lib/natty-ui/helper/table.rb', line 368 def bottom_padding = @padding[2] |
#eol ⇒ Boolean
Whether line breaks inside the text are collapsed to spaces.
48 49 50 |
# File 'lib/natty-ui/helper/table.rb', line 48 def eol @eol end |
#height ⇒ Integer, ...
Height constraint for this cell.
Returns an exact Integer when both bounds are equal, a Range when
they differ, or nil when neither is set.
252 253 254 255 |
# File 'lib/natty-ui/helper/table.rb', line 252 def height return @min_height if @min_height == @max_height (@min_height..@max_height) if @min_height || @max_height end |
#max_height ⇒ Integer?
Maximum row height in lines for this cell.
218 219 220 |
# File 'lib/natty-ui/helper/table.rb', line 218 def max_height @max_height end |
#max_width ⇒ Integer, ...
Maximum column width in characters for this cell.
119 120 121 |
# File 'lib/natty-ui/helper/table.rb', line 119 def max_width @max_width end |
#min_height ⇒ Integer?
Minimum row height in lines for this cell.
197 198 199 |
# File 'lib/natty-ui/helper/table.rb', line 197 def min_height @min_height end |
#min_width ⇒ Integer, ...
Minimum column width in characters for this cell.
99 100 101 |
# File 'lib/natty-ui/helper/table.rb', line 99 def min_width @min_width end |
#padding ⇒ Array(Integer, Integer, Integer, Integer)
Cell padding as a four-element array [top, right, bottom, left].
297 298 299 |
# File 'lib/natty-ui/helper/table.rb', line 297 def padding @padding end |
#padding_left ⇒ Integer
Left padding in characters.
380 |
# File 'lib/natty-ui/helper/table.rb', line 380 def left_padding = @padding[3] |
#right_padding ⇒ Integer
Right padding in characters.
356 |
# File 'lib/natty-ui/helper/table.rb', line 356 def right_padding = @padding[1] |
#spaces ⇒ Boolean
Whether whitespace are preserved.
59 60 61 |
# File 'lib/natty-ui/helper/table.rb', line 59 def spaces @spaces end |
#top_padding ⇒ Integer
Top padding in lines.
344 |
# File 'lib/natty-ui/helper/table.rb', line 344 def top_padding = @padding[0] |
#vertical ⇒ :top, ...
Vertical text alignment within the cell.
83 84 85 |
# File 'lib/natty-ui/helper/table.rb', line 83 def vertical @vertical end |
#width ⇒ Integer, ...
Width constraint for this cell.
Returns an exact Integer or Float when min_width equals
max_width, a Range when they differ, or nil when neither is set.
152 153 154 155 |
# File 'lib/natty-ui/helper/table.rb', line 152 def width return @min_width if @min_width == @max_width (@min_width..@max_width) if @min_width || @max_width end |
Instance Method Details
#assign(attributes) ⇒ Cell::Attributes
Applies attribute values from a hash.
416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/natty-ui/helper/table.rb', line 416 def assign(attributes) attributes = attributes.to_hash unless attributes.empty? @eol = false if attributes[:eol] == false @spaces = false if attributes[:spaces] == false self.align = attributes[:align] if attributes.key?(:align) self.vertical = attributes[:vertical] if attributes.key?(:vertical) assign_padding(attributes) assign_width(attributes) assign_height(attributes) end self end |
#empty? ⇒ Boolean
Returns true when all attributes are at their default values.
391 392 393 394 |
# File 'lib/natty-ui/helper/table.rb', line 391 def empty? @align.nil? && @vertical.nil? && @min_width.nil? && @max_width.nil? && @min_height.nil? && @max_height.nil? && @padding.all?(&:zero?) end |
#left_padding ⇒ Integer
Left padding in characters.
380 |
# File 'lib/natty-ui/helper/table.rb', line 380 def left_padding = @padding[3] |