Class: Multisync::List
- Inherits:
-
Object
show all
- Includes:
- Colors
- Defined in:
- lib/multisync/list.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Colors
#as_fail, #as_main, #as_note, #as_skipped, #as_success
Constructor Details
#initialize(tasks) ⇒ List
Returns a new instance of List.
10
11
12
|
# File 'lib/multisync/list.rb', line 10
def initialize tasks
@tasks = tasks
end
|
Instance Attribute Details
#catalog ⇒ Object
5
6
7
|
# File 'lib/multisync/list.rb', line 5
def catalog
@catalog
end
|
#tasks ⇒ Object
8
9
10
|
# File 'lib/multisync/list.rb', line 8
def tasks
@tasks
end
|
Instance Method Details
#descriptions(task) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/multisync/list.rb', line 36
def descriptions task
if [task.source_description, task.destination_description].any?(&:empty?)
["", "", ""]
else
[task.source_description, "-->", task.destination_description].map(&method(:as_note))
end
end
|
#rows ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/multisync/list.rb', line 22
def rows
tasks.map do |task|
next unless task.level > 0
indent = "".ljust(2 * (task.level - 1), " ")
name = task.executeable? ? task.name : "#{task.name}#{as_note("/")}"
default = task.default? ? as_note(" *") : ""
[
[indent, name, default].join,
*descriptions(task)
]
end
end
|
#table ⇒ Object
18
19
20
|
# File 'lib/multisync/list.rb', line 18
def table
Terminal::Table.new(rows: rows, style: table_style)
end
|
#table_style ⇒ Object
44
45
46
|
# File 'lib/multisync/list.rb', line 44
def table_style
{border_x: as_note("─"), border_y: "", border_i: "", border_top: false, border_bottom: false, padding_left: 0, padding_right: 3}
end
|
#to_s ⇒ Object
14
15
16
|
# File 'lib/multisync/list.rb', line 14
def to_s
"\n" + table.to_s
end
|