Class: Multisync::Summary
- Inherits:
-
Object
- Object
- Multisync::Summary
- Defined in:
- lib/multisync/summary.rb
Instance Attribute Summary collapse
-
#tasks ⇒ Object
readonly
All tasks to include in the summary.
Instance Method Summary collapse
- #data ⇒ Object
- #headings ⇒ Object
-
#initialize(tasks) ⇒ Summary
constructor
A new instance of Summary.
- #table ⇒ Object
- #table_style ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(tasks) ⇒ Summary
Returns a new instance of Summary.
6 7 8 |
# File 'lib/multisync/summary.rb', line 6 def initialize tasks @tasks = tasks end |
Instance Attribute Details
#tasks ⇒ Object (readonly)
All tasks to include in the summary
4 5 6 |
# File 'lib/multisync/summary.rb', line 4 def tasks @tasks end |
Instance Method Details
#data ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/multisync/summary.rb', line 22 def data tasks.map do |task| result = task.result desc = [task.source_description, "--> #{task.destination_description}"] case result[:action] when :run if result[:status] && result[:status].success? # successfull run stats = Multisync::RsyncStat.new(result[:stdout]) [*desc, *stats.formatted_values.map{|e| {value: e.color(:green), alignment: :right} } ] else # failed or interrupted run [*desc, { value: (result[:stderr] || 'n/a').strip.color(:red), colspan: 6 } ] end when :skip # skiped sync [*desc, { value: result[:skip_message].color(:yellow), colspan: 6 } ] else # not executed [*desc, { value: 'not executed'.faint, colspan: 6 } ] end end.push ["Total".faint, "", *Multisync::RsyncStat.formatted_totals.map{|e| {value: e.faint, alignment: :right} } ] end |
#headings ⇒ Object
18 19 20 |
# File 'lib/multisync/summary.rb', line 18 def headings %w( Source Destination Files + - → ∑ ↑ ).zip(%i( left left right right right right right right )).map{|v,a| {value: v, alignment: a} } end |
#table ⇒ Object
14 15 16 |
# File 'lib/multisync/summary.rb', line 14 def table Terminal::Table.new(headings: headings, rows: data, style: table_style) end |
#table_style ⇒ Object
49 50 51 |
# File 'lib/multisync/summary.rb', line 49 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
10 11 12 |
# File 'lib/multisync/summary.rb', line 10 def to_s table.to_s end |