Skip to content

Commit

Permalink
Merge pull request #26 from kmcgrady/emptylines
Browse files Browse the repository at this point in the history
Update to_s to insert an additional new line for no text
  • Loading branch information
cpetersen committed Apr 9, 2018
2 parents 69611ad + 333ccc6 commit daf7cdc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/srt/line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def webvtt_time_str
end

def to_s(time_str_function=:time_str)
[sequence, (display_coordinates ? send(time_str_function) + display_coordinates : send(time_str_function)), text, ''].flatten.join("\n")
content = text.empty? ? [''] : text
coordinates = display_coordinates ? display_coordinates : ""
[sequence, send(time_str_function) + coordinates, content, ""].flatten.join("\n")
end
end
end
16 changes: 16 additions & 0 deletions spec/line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@
expect(line.time_str).to eq("00:03:44,200 --> 00:04:04,578")
end
end

describe "#to_s" do
let(:line) { SRT::Line.new }

before do
line.sequence = "1"
line.start_time = 224.2
line.end_time = 244.578
end

context "with empty content" do
it "creates a valid empty node" do
expect(line.to_s).to eq("1\n00:03:44,200 --> 00:04:04,578\n\n")
end
end
end
end

0 comments on commit daf7cdc

Please sign in to comment.