Class: MonoclePrint::List
- Inherits:
-
Object
- Object
- MonoclePrint::List
show all
- Includes:
- Presentation
- Defined in:
- lib/monocle-print/list.rb
Constant Summary
Presentation::ALIGNMENTS
COLOR_ESCAPE, FOUR_BYTES, MULTIBYTE_CHARACTER, ONE_BYTE, THREE_BYTES, TWO_BYTES, VERSION
Instance Attribute Summary
Attributes included from Presentation
#max_width, #owner
Instance Method Summary
collapse
#alignment, #alignment=, #height, included, #output, #output=, #render, #style, #style=, #to_s, #width
Line, Output, Rectangle, Style, Text, buffer, included, library_path, stderr, stdout, version
Constructor Details
#initialize(*items) ⇒ List
Returns a new instance of List.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/monocle-print/list.rb', line 8
def initialize( *items )
@spacer = nil
@columns = nil
items = [ items ].flatten!
options = items.last.is_a?( Hash ) ? items.pop : nil
initialize_view( options )
@items = items.map! { | item | SingleLine.new( item ) }
@sorted = nil
if options
value = options[ :column_spacer ] and self.column_spacing = value
value = options[ :columns ] and self.columns = value
end
block_given? and yield( self )
end
|
Instance Method Details
#columns(n = nil) ⇒ Object
48
49
50
51
|
# File 'lib/monocle-print/list.rb', line 48
def columns( n = nil )
n and self.columns = n
@columns or optimize_columns
end
|
#columns=(n) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/monocle-print/list.rb', line 53
def columns= n
@columns =
case n
when nil then n
else Utils.at_least( n.to_i, 1 )
end
end
|
#spacer(value = nil) ⇒ Object
26
27
28
29
|
# File 'lib/monocle-print/list.rb', line 26
def spacer( value = nil )
value and self.column_spacer = value
@spacer or SingleLine.new( ' ' )
end
|
#spacer=(value) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/monocle-print/list.rb', line 31
def spacer= value
@spacer =
case value
when nil, SingleLine then value
else SingleLine.new( value )
end
end
|
#spacing(n) ⇒ Object
39
40
41
42
|
# File 'lib/monocle-print/list.rb', line 39
def spacing( n )
self.spacing = n
spacer.width
end
|
#spacing=(width) ⇒ Object
44
45
46
|
# File 'lib/monocle-print/list.rb', line 44
def spacing= width
self.spacer = ' ' * Utils.at_least( width.to_i, 0 )
end
|