Class: Ehbrs::Videos::File

Inherits:
Object
  • Object
show all
Defined in:
lib/ehbrs/videos/file.rb

Direct Known Subclasses

Unsupported::File

Constant Summary collapse

TIME_PATTERN =
/(\d+):(\d{2}):(\d{2})(?:\.(\d+))/.freeze

Class Method Summary collapse

Class Method Details

.seconds_to_time(seconds) ⇒ Object



15
16
17
18
# File 'lib/ehbrs/videos/file.rb', line 15

def seconds_to_time(seconds)
  t = seconds.floor
  hmsf_to_time((t / 3600), ((t / 60) % 60), (t % 60), (seconds - t).round(3))
end

.time_to_seconds(time) ⇒ Object



20
21
22
23
24
25
# File 'lib/ehbrs/videos/file.rb', line 20

def time_to_seconds(time)
  m = TIME_PATTERN.match(time)
  raise "Time pattern not find in \"#{time}\"" unless m

  hmsf_to_seconds(m[1], m[2], m[3], m[4])
end