From 84d4a1eef9d445f7c8a63794d0a561a7cf477dff Mon Sep 17 00:00:00 2001 From: Jonathan Rochkind Date: Tue, 10 Jun 2025 16:01:47 -0400 Subject: [PATCH] Add examples to README of getting cue times in seconds, and reading from string --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c398f81..50e3798 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,11 @@ To parse a webvtt file: require "webvtt" webvtt = WebVTT.read("path/sub.vtt") + webvtt.cues.each do |cue| puts "identifier: #{cue.identifier}" - puts "Start: #{cue.start}" - puts "End: #{cue.end}" + puts "Start: #{cue.start.to_s}, #{cue.start.to_f} seconds" + puts "End: #{cue.end.to_s}, #{cue.end.to_f} seconds" puts "Style: #{cue.style.inspect}" puts "Text: #{cue.text}" puts "Plain text: #{cue.plain_text}" # text without style tags if any @@ -35,6 +36,12 @@ webvtt.cues.each do |cue| end ``` +To read from a string: + +```ruby +webvtt == WebVTT.from_blog(string) +``` + ## Converting from SRT You can also convert an SRT file to a standard WebVTT file: