Class: Media::Command::Progress
- Inherits:
-
Object
- Object
- Media::Command::Progress
- 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
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #complete {|_self| ... } ⇒ Object
-
#initialize(args = {}) ⇒ Progress
constructor
A new instance of Progress.
- #to_f ⇒ Object
- #update(line) ⇒ Object
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
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
8 9 10 |
# File 'lib/media/command/progress.rb', line 8 def duration @duration end |
#time ⇒ Object (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
26 27 28 29 |
# File 'lib/media/command/progress.rb', line 26 def complete @time = @duration yield self if block_given? end |
#to_f ⇒ Object
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 |