Class: Multisync::List
- Inherits:
-
Object
- Object
- Multisync::List
- Defined in:
- lib/multisync/list.rb
Instance Attribute Summary collapse
-
#catalog ⇒ Object
readonly
Given catalog.
-
#tasks ⇒ Object
readonly
Tasks.
Instance Method Summary collapse
- #description(subject) ⇒ Object
-
#initialize(catalog) ⇒ List
constructor
A new instance of List.
- #table ⇒ Object
- #table_style ⇒ Object
- #to_s ⇒ Object
- #visit(subject, level) ⇒ Object
Constructor Details
#initialize(catalog) ⇒ List
Returns a new instance of List.
12 13 14 15 |
# File 'lib/multisync/list.rb', line 12 def initialize catalog @catalog = catalog @tasks = [] end |
Instance Attribute Details
#catalog ⇒ Object (readonly)
Given catalog
7 8 9 |
# File 'lib/multisync/list.rb', line 7 def catalog @catalog end |
#tasks ⇒ Object (readonly)
Tasks
10 11 12 |
# File 'lib/multisync/list.rb', line 10 def tasks @tasks end |
Instance Method Details
#description(subject) ⇒ Object
36 37 38 39 |
# File 'lib/multisync/list.rb', line 36 def description subject desc = [subject.source_description, subject.destination_description] desc.any?(&:empty?) ? [] : [desc.first, ['--> ', desc.last].join] end |
#table ⇒ Object
22 23 24 |
# File 'lib/multisync/list.rb', line 22 def table Terminal::Table.new(rows: tasks, style: table_style) end |
#table_style ⇒ Object
41 42 43 |
# File 'lib/multisync/list.rb', line 41 def table_style { border_top: false, border_bottom: false, border_x: '–', border_y: '', border_i: '', padding_left: 0, padding_right: 3 } end |
#to_s ⇒ Object
17 18 19 20 |
# File 'lib/multisync/list.rb', line 17 def to_s catalog.traverse self table.to_s end |
#visit(subject, level) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/multisync/list.rb', line 26 def visit subject, level if level > 0 tab = ''.ljust(2*(level-1), ' ') default = subject.default? ? ' *' : '' name = "#{tab}#{subject.name}#{default}" tasks << [name, *description(subject).map(&:faint)] # puts "#{name.ljust(32, ' ')}#{description(subject)}" end end |