Class: Transcode::Reporter
- Inherits:
-
Object
- Object
- Transcode::Reporter
- Defined in:
- lib/transcode/reporter.rb
Overview
Formats and prints the summary table.
Instance Method Summary collapse
- #add(file, res, aud = 0, sub = 0, tit = 0) ⇒ Object
- #do ⇒ Object
- #head ⇒ Object
-
#initialize(act, tit, wid) ⇒ Reporter
constructor
A new instance of Reporter.
- #stat ⇒ Object
- #table ⇒ Object
Constructor Details
#initialize(act, tit, wid) ⇒ Reporter
Returns a new instance of Reporter.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/transcode/reporter.rb', line 14 def initialize(act, tit, wid) @act = act @tit = tit @tbl = wid @ttl = @tbl - 4 @str = (@tbl - 7) / 2 @row = [] @tim = Timer.new @sta = { converted: 0, failed: 0 } end |
Instance Method Details
#add(file, res, aud = 0, sub = 0, tit = 0) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/transcode/reporter.rb', line 25 def add(file, res, aud = 0, sub = 0, tit = 0) row = [Utils.trim(File.basename(file), @str)] if aud != 0 || sub != 0 (row << [ { value: aud, alignment: :right }, { value: sub, alignment: :right }, { value: tit, alignment: :right } ]).flatten! end @row << row @sta[res ? :converted : :failed] += 1 end |
#do ⇒ Object
59 60 61 62 63 |
# File 'lib/transcode/reporter.rb', line 59 def do msg = "#{@act ? 'Real' : 'Test'}:#{stat} in #{@tim.read}." msg = Utils.trim(msg, @ttl) puts "#{table}\n| #{msg}#{' ' * (@ttl - msg.length)} |\n+-#{'-' * @ttl}-+" end |
#head ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/transcode/reporter.rb', line 38 def head head = [{ value: 'file', alignment: :center }] if @row.first.size == 4 (head << [ { value: 'audio', alignment: :center }, { value: 'subtitles', alignment: :center }, { value: 'titles', alignment: :center } ]).flatten! end head end |
#stat ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/transcode/reporter.rb', line 65 def stat out = '' @sta.each do |k, v| out += " #{v} #{k}," if v.positive? end out.chop end |