From 2bb368cdf3a2d5f3fc95ccc12fd6652226a77af2 Mon Sep 17 00:00:00 2001 From: Yohei Yasukawa Date: Thu, 18 Dec 2025 15:46:57 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E3=83=8B=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E3=82=BF=E3=82=A4=E3=83=88=E3=83=AB=E3=81=AB=E3=80=8C?= =?UTF-8?q?=E5=AF=84=E8=B4=88=E3=80=8D=E3=81=8C=E5=90=AB=E3=81=BE=E3=82=8C?= =?UTF-8?q?=E3=82=8B=E5=A0=B4=E5=90=88=E3=81=AF=20=F0=9F=8E=81=20=E7=B5=B5?= =?UTF-8?q?=E6=96=87=E5=AD=97=E3=82=92=E4=BB=98=E4=B8=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit News#formatted_title メソッドを改善: - タイトルに「寄贈」が含まれる場合は 🎁 絵文字を表示 - ただし、ポッドキャストやPR TIMESのURLは優先される - PC寄贈やその他の寄贈関連ニュースが視覚的に識別しやすくなる 優先順位: 1. ポッドキャストURL → 📻 2. PR TIMES URL → 📢 3. タイトルに「寄贈」 → 🎁 4. その他 → 📰 --- app/models/news.rb | 7 ++++--- spec/models/news_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/models/news.rb b/app/models/news.rb index 0bd5fa84..060549d7 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -12,11 +12,12 @@ def formatted_title return title if has_custom_emoji # Add preset Emoji to its prefix if title does not have Emoji. - emoji = case url - when %r{/podcasts/\d+} + emoji = if url.match?(%r{/podcasts/\d+}) '📻' - when %r{prtimes\.jp} + elsif url.match?(%r{prtimes\.jp}) '📢' + elsif title.include?('寄贈') + '🎁' else '📰' end diff --git a/spec/models/news_spec.rb b/spec/models/news_spec.rb index e3691be4..d89242c9 100644 --- a/spec/models/news_spec.rb +++ b/spec/models/news_spec.rb @@ -84,6 +84,16 @@ end context '先頭文字が絵文字でない場合' do + it 'タイトルに「寄贈」が含まれる場合は🎁を付与する' do + news = build(:news, title: 'ノートPC 233台を寄贈しました', url: 'https://news.coderdojo.jp/2025/12/18/pc-donation') + expect(news.formatted_title).to eq '🎁 ノートPC 233台を寄贈しました' + end + + it 'ポッドキャストURLはタイトルの「寄贈」より優先される' do + news = build(:news, title: 'ポッドキャストで寄贈について話しました', url: 'https://coderdojo.jp/podcasts/50') + expect(news.formatted_title).to eq '📻 ポッドキャストで寄贈について話しました' + end + it 'ポッドキャストのURLには📻を付与する' do news = build(:news, title: 'エピソード33', url: 'https://coderdojo.jp/podcasts/33') expect(news.formatted_title).to eq '📻 エピソード33'