Class: CaptionCrunch::Adapters::VTT
- Inherits:
-
Object
- Object
- CaptionCrunch::Adapters::VTT
- Defined in:
- lib/caption_crunch/adapters/vtt.rb
Constant Summary collapse
- SIGNATURE_REGEX =
/\AWEBVTT\Z|\AWEBVTT[ \t\n]/.freeze
- COMMENT_REGEX =
/\ANOTE\Z|\ANOTE[ \t\n]/.freeze
- ARROW_REGEX =
/-->/.freeze
- TIME_REGEX =
Format: hour:minute:second.milliseconds
hour: is optional. 11:22:33 00:11:22:333 102:01:43:204
/\A(?:(\d\d+):)?([0-5]\d):([0-5]\d)\.(\d\d\d)\Z/.freeze
- NEWLINE_REGEX =
/\n/.freeze
Class Method Summary collapse
-
.parse(file) ⇒ Object
Reads a file (or string) and returns a CaptionCrunch::Track instance.
Class Method Details
.parse(file) ⇒ Object
Reads a file (or string) and returns a CaptionCrunch::Track instance. Raises CaptionCrunch::ParseError if the input is malformed.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/caption_crunch/adapters/vtt.rb', line 19 def parse(file) contents = remove_bom(read_file(file)) normalized = normalize_linefeeds(contents) segments = split_segments(normalized) ensure_signature(segments.shift) Track.new.tap do |track| segments.each do |segment| next if comment?(segment) track.cues << parse_cue(segment) end end end |