Skip to content

Commit c7bae3f

Browse files
committed
Add guard condition for Podcast::YOUTUBE_ID_REGEX
1 parent a4f661d commit c7bae3f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

app/controllers/podcasts_controller.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,18 @@ def show
3535
private
3636

3737
def convert_shownote(content)
38-
youtube_id = @episode.content.match(/watch\?v=((\w)*)/)[1]
39-
4038
shownote = <<~HTML
4139
<h2 id='shownote'>
4240
<a href='#shownote'>🎤</a>
4341
Shownote
4442
<small>(話したこと)</small>
4543
</h2>
4644
HTML
47-
4845
content.gsub!(/(#+) Shownote/) { shownote }
49-
return content unless content.match?(Podcast::TIMESTAMP_REGEX)
5046

47+
return content unless content.match?(Podcast::YOUTUBE_ID_REGEX)
48+
return content unless content.match?(Podcast::TIMESTAMP_REGEX)
49+
youtube_id = @episode.content.match(Podcast::YOUTUBE_ID_REGEX)[1]
5150
content.gsub!(Podcast::TIMESTAMP_REGEX) do
5251
t = $1
5352
t = (t.size == '0:00'.size) ? '0' + t : t

app/models/podcast.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ class Podcast < ApplicationRecord
22
self.table_name = 'podcasts'
33
DIR_PATH = 'public/podcasts'
44
WDAY2JAPANESE = %w( )
5-
TIMESTAMP_REGEX = /-\s((\d:)?\d{1,}:\d{2})/
5+
TIMESTAMP_REGEX = /-\s((\d:)?\d{1,}:\d{2})/
6+
YOUTUBE_ID_REGEX = /watch\?v=((\w)*)/
67

78
validates :title, presence: true
89
validates :content_size, presence: true

0 commit comments

Comments
 (0)