Class: Vidibus::Timecode

Inherits:
Object
  • Object
show all
Defined in:
lib/vidibus/timecode.rb

Defined Under Namespace

Classes: Error, FormatError, InputError

Constant Summary collapse

VERSION =
'0.1.1'
YEAR_REGEXP =
/(\d{3,4}(?:[,\-]\d{3,4})?)/
MONTH_REGEXP =
/(\d{1,2}(?:[,\-]\d{1,2})?)/
DAY_REGEXP =
/(\d{1,2}(?:[,\-]\d{1,2})?)/
TIME_REGEXP =
/(\d{1,2}(?:[,\-]\d{1,2})?)/
REGEXP =
/^(?:#{YEAR_REGEXP}\/)?(?:#{MONTH_REGEXP}\/)?#{DAY_REGEXP}@#{TIME_REGEXP}(?:\:#{TIME_REGEXP})?(?:\:#{TIME_REGEXP})?$/

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Timecode

Returns a new instance of Timecode.



15
16
17
18
19
# File 'lib/vidibus/timecode.rb', line 15

def initialize(*args)
  @options = extract_options!(args) || {}
  @input = args.first or raise_input_error
  process_input
end

Instance Method Details

#timeObject



29
30
31
# File 'lib/vidibus/timecode.rb', line 29

def time
  @time ||= parse_timecode
end

#timecodeObject



21
22
23
24
25
26
27
# File 'lib/vidibus/timecode.rb', line 21

def timecode
  @timecode ||= begin
    format = '%Y/%m/%d@%H:%M'
    format << ':%S' if @options[:precision].to_s == 'seconds'
    @time.strftime(format)
  end
end