Class: Media::Command::Progress

Inherits:
Object
  • Object
show all
Defined in:
lib/media/command/progress.rb

Constant Summary collapse

DURATION =
/Duration: (\d+):(\d+):(\d+.\d+), start: (\d+.\d+)/
TIME =
/time=(\d+):(\d+):(\d+.\d+)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Progress

Returns a new instance of Progress.



10
11
12
13
# File 'lib/media/command/progress.rb', line 10

def initialize(args={})
  @duration = args.fetch(:duration, 0.0)
  @time     = args.fetch(:time, 0.0)
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



8
9
10
# File 'lib/media/command/progress.rb', line 8

def duration
  @duration
end

#timeObject (readonly)

Returns the value of attribute time.



8
9
10
# File 'lib/media/command/progress.rb', line 8

def time
  @time
end

Instance Method Details

#complete {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



26
27
28
29
# File 'lib/media/command/progress.rb', line 26

def complete
  @time = @duration
  yield self if block_given?
end

#to_fObject



31
32
33
# File 'lib/media/command/progress.rb', line 31

def to_f
  time / duration rescue ZeroDivisionError 0.0
end

#update(line) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/media/command/progress.rb', line 15

def update(line)
  case line
  when DURATION
    @duration = ($1.to_i * 3600) + ($2.to_i * 60) + $3.to_f + $4.to_f
    yield self if block_given?
  when TIME
    @time = ($1.to_i * 3600) + ($2.to_i * 60) + $3.to_f
    yield self if block_given?
  end
end