Module: JobsHelper

Defined in:
app/helpers/jobs_helper.rb

Instance Method Summary collapse

Instance Method Details

#compression_rate(job) ⇒ Object


23
24
25
26
# File 'app/helpers/jobs_helper.rb', line 23

def compression_rate(job)
  pct = (destination_filesize(job).to_f / job.filesize.to_f) * 100.0
  format '%.2f', pct
end

#destination_filesize(job) ⇒ Object


11
12
13
14
15
# File 'app/helpers/jobs_helper.rb', line 11

def destination_filesize(job)
  File.size(job.destination_file)
rescue Errno::ENOENT
  'unknown (file gone)'
end

#encoding_time(job) ⇒ Object


6
7
8
9
# File 'app/helpers/jobs_helper.rb', line 6

def encoding_time(job)
  time = job.completed_at.to_i - job.transcoding_started_at.to_i
  time < 0 ? 0 : time
end

#notified_at(notification, job) ⇒ Object


17
18
19
20
21
# File 'app/helpers/jobs_helper.rb', line 17

def notified_at(notification, job)
  return nil if notification.notified_at.blank?
  num = notification.notified_at.to_i - job.completed_at.to_i
  num <= 0 ? '00:00:00' : number_to_time(num)
end

#number_to_time(seconds) ⇒ Object


28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/jobs_helper.rb', line 28

def number_to_time(seconds)
  return nil if seconds.to_i < 1
  time = Time.at(seconds).utc
  if seconds > 86_400
    days = seconds / 3600 / 24
    "#{format '%02d', days}:#{time.strftime('%H:%M:%S')}"
  else
    time.strftime('%H:%M:%S')
  end
end

#progress_as_percentage(progress) ⇒ Object


2
3
4
# File 'app/helpers/jobs_helper.rb', line 2

def progress_as_percentage(progress)
  format '%.2f', (progress.to_f * 100.0)
end