Class: Multisync::List

Inherits:
Object
  • Object
show all
Defined in:
lib/multisync/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#catalogObject (readonly)

Given catalog



7
8
9
# File 'lib/multisync/list.rb', line 7

def catalog
  @catalog
end

#tasksObject (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

#tableObject



22
23
24
# File 'lib/multisync/list.rb', line 22

def table
  Terminal::Table.new(rows: tasks, style: table_style)
end

#table_styleObject



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_sObject



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