Class: MonoclePrint::Table::Column
- Inherits:
-
Object
- Object
- MonoclePrint::Table::Column
show all
- Includes:
- MonoclePrint
- Defined in:
- lib/monocle-print/table/column.rb
Constant Summary
COLOR_ESCAPE, FOUR_BYTES, MULTIBYTE_CHARACTER, ONE_BYTE, MonoclePrint::THREE_BYTES, MonoclePrint::TWO_BYTES, VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Line, Output, Rectangle, Style, Text, buffer, included, library_path, stderr, stdout, version
Constructor Details
#initialize(table, index) ⇒ Column
Returns a new instance of Column.
9
10
11
12
13
14
15
16
17
|
# File 'lib/monocle-print/table/column.rb', line 9
def initialize( table, index )
@table = table
@index = index
@wrap = false
@flow = false
@alignment = :left
@fixed_width = nil
@cached_width = nil
end
|
Instance Attribute Details
#alignment ⇒ Object
Returns the value of attribute alignment.
20
21
22
|
# File 'lib/monocle-print/table/column.rb', line 20
def alignment
@alignment
end
|
#index ⇒ Object
Returns the value of attribute index.
19
20
21
|
# File 'lib/monocle-print/table/column.rb', line 19
def index
@index
end
|
#table ⇒ Object
Returns the value of attribute table.
19
20
21
|
# File 'lib/monocle-print/table/column.rb', line 19
def table
@table
end
|
Instance Method Details
#calculate_metrics ⇒ Object
83
84
85
|
# File 'lib/monocle-print/table/column.rb', line 83
def calculate_metrics
@cached_width = @fixed_width || calculate_width
end
|
#cells ⇒ Object
48
49
50
|
# File 'lib/monocle-print/table/column.rb', line 48
def cells
@table.grep( Row ) { | row | row[ @index ] || Line( '' ) }
end
|
#clear_metrics ⇒ Object
87
88
89
|
# File 'lib/monocle-print/table/column.rb', line 87
def clear_metrics
@cached_width = nil
end
|
#first? ⇒ Boolean
60
61
62
|
# File 'lib/monocle-print/table/column.rb', line 60
def first?
@index.zero?
end
|
#fixed=(bool) ⇒ Object
40
41
42
|
# File 'lib/monocle-print/table/column.rb', line 40
def fixed=( bool )
self.malleable = !bool
end
|
#fixed? ⇒ Boolean
36
37
38
|
# File 'lib/monocle-print/table/column.rb', line 36
def fixed?
not malleable?
end
|
#last? ⇒ Boolean
64
65
66
|
# File 'lib/monocle-print/table/column.rb', line 64
def last?
@index == (table.columns.length - 1)
end
|
#malleable=(bool) ⇒ Object
32
33
34
|
# File 'lib/monocle-print/table/column.rb', line 32
def malleable=( bool )
@wrap = @flow = bool
end
|
#malleable? ⇒ Boolean
28
29
30
|
# File 'lib/monocle-print/table/column.rb', line 28
def malleable?
@wrap and @flow
end
|
#next_column ⇒ Object
56
57
58
|
# File 'lib/monocle-print/table/column.rb', line 56
def next_column
@table.columns[ @index + 1 ]
end
|
#prepare(cell_text) ⇒ Object
68
69
70
71
72
73
|
# File 'lib/monocle-print/table/column.rb', line 68
def prepare( cell_text )
cell_text = cell_text ? cell_text.dup : Text( ' ' )
@flow and cell_text.reflow!( false )
@wrap and cell_text = cell_text.wrap( width - 1 )
cell_text.align!( @alignment, width )
end
|
#previous_column ⇒ Object
52
53
54
|
# File 'lib/monocle-print/table/column.rb', line 52
def previous_column
@index.zero? ? nil : @table.columns[ @index - 1 ]
end
|
#title ⇒ Object
44
45
46
|
# File 'lib/monocle-print/table/column.rb', line 44
def title
@table.titles[ @index ]
end
|
#width ⇒ Object
79
80
81
|
# File 'lib/monocle-print/table/column.rb', line 79
def width
@fixed_width or @cached_width or calculate_width
end
|
#width=(w) ⇒ Object
75
76
77
|
# File 'lib/monocle-print/table/column.rb', line 75
def width=( w )
@fixed_width = Utils.at_least( w.to_i, 1 )
end
|