Class: FLV::TimestampRange

Inherits:
Range
  • Object
show all
Defined in:
lib/flvedit/flv/timestamp.rb

Constant Summary collapse

REGEXP =
Regexp.new("^(#{core})-(#{core})$").freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Range

#==

Constructor Details

#initialize(from, to, exclusive = false) ⇒ TimestampRange

Returns a new instance of TimestampRange.



79
80
81
# File 'lib/flvedit/flv/timestamp.rb', line 79

def initialize(from, to, exclusive=false)
  super(Timestamp.try_convert(from), Timestamp.try_convert(to, INFINITY), exclusive)
end

Class Method Details

.try_convert(s) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/flvedit/flv/timestamp.rb', line 91

def self.try_convert(s)
  case s
  when Range
    new s.begin, s.end
  when TimestampRange
    s
  when REGEXP
    new *Regexp.last_match.captures
  else
    p "Can't convert #{s}"
  end
end

Instance Method Details

#in_millisecondsObject



87
88
89
# File 'lib/flvedit/flv/timestamp.rb', line 87

def in_milliseconds
  Range.new(self.begin.in_milliseconds, self.end.in_milliseconds, self.exclude_end?)
end

#in_secondsObject



83
84
85
# File 'lib/flvedit/flv/timestamp.rb', line 83

def in_seconds
  Range.new(self.begin.in_seconds, self.end.in_seconds, self.exclude_end?)      
end

#to_sObject



75
76
77
# File 'lib/flvedit/flv/timestamp.rb', line 75

def to_s
  "#{self.begin}-#{self.end}"
end

#widen(amount) ⇒ Object



104
105
106
# File 'lib/flvedit/flv/timestamp.rb', line 104

def widen(amount)
  TimestampRange.new [self.begin - amount, 0].max, self.end + amount, self.exclude_end?
end