Skip to content

Commit

Permalink
Add guard condition for Podcast::YOUTUBE_ID_REGEX
Browse files Browse the repository at this point in the history
  • Loading branch information
yasulab committed Jan 29, 2025
1 parent a4f661d commit c7bae3f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 3 additions & 4 deletions app/controllers/podcasts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ def show
private

def convert_shownote(content)
youtube_id = @episode.content.match(/watch\?v=((\w)*)/)[1]

shownote = <<~HTML
<h2 id='shownote'>
<a href='#shownote'>🎤</a>
Shownote
<small>(話したこと)</small>
</h2>
HTML

content.gsub!(/(#+) Shownote/) { shownote }
return content unless content.match?(Podcast::TIMESTAMP_REGEX)

return content unless content.match?(Podcast::YOUTUBE_ID_REGEX)
return content unless content.match?(Podcast::TIMESTAMP_REGEX)
youtube_id = @episode.content.match(Podcast::YOUTUBE_ID_REGEX)[1]
content.gsub!(Podcast::TIMESTAMP_REGEX) do
t = $1
t = (t.size == '0:00'.size) ? '0' + t : t
Expand Down
3 changes: 2 additions & 1 deletion app/models/podcast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ class Podcast < ApplicationRecord
self.table_name = 'podcasts'
DIR_PATH = 'public/podcasts'
WDAY2JAPANESE = %w( )
TIMESTAMP_REGEX = /-\s((\d:)?\d{1,}:\d{2})/
TIMESTAMP_REGEX = /-\s((\d:)?\d{1,}:\d{2})/
YOUTUBE_ID_REGEX = /watch\?v=((\w)*)/

validates :title, presence: true
validates :content_size, presence: true
Expand Down

0 comments on commit c7bae3f

Please sign in to comment.