Class: Transcode::Reporter
- Inherits:
-
Object
- Object
- Transcode::Reporter
- Defined in:
- lib/transcode/reporter.rb
Overview
Formats and prints output data.
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.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/transcode/reporter.rb', line 12 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
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/transcode/reporter.rb', line 23 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
57 58 59 60 61 |
# File 'lib/transcode/reporter.rb', line 57 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
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/transcode/reporter.rb', line 36 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
63 64 65 66 67 68 69 |
# File 'lib/transcode/reporter.rb', line 63 def stat out = '' @sta.each do |k, v| out += ' ' + v.to_s + ' ' + k.to_s + ',' if v.positive? end out.chop end |