Skip to content

Commit dd0d0b9

Browse files
committed
rubocopからの指摘「Metrics/CyclomaticComplexity」に対処するために、処理を関数に切り分けた
1 parent 1ed1f46 commit dd0d0b9

1 file changed

Lines changed: 18 additions & 26 deletions

File tree

app/notifiers/discord_notifier.rb

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,39 +39,17 @@ def announced(params = {})
3939
)
4040
end
4141

42-
# rubocop:disable Metrics/MethodLength
4342
def coming_soon_regular_events(params = {})
4443
params.merge!(@params)
4544
webhook_url = params[:webhook_url] || Rails.application.secrets[:webhook][:all]
4645
today_events = params[:today_events] || RegularEvent.today_events
4746
tomorrow_events = params[:tomorrow_events] || RegularEvent.tomorrow_events
48-
day_of_the_week = %w[ ]
4947
today = Time.current
5048
tomorrow = Time.current.next_day
51-
is_outputted_event = false
5249
event_info = "⚡️⚡️⚡️イベントのお知らせ⚡️⚡️⚡️\n\n"
53-
if today_events.present?
54-
today_events.each_with_index do |event, index|
55-
unless HolidayJp.holiday?(today) && !event.hold_national_holiday?
56-
event_info += "< 今日 (#{today.strftime('%m/%d')} #{day_of_the_week[today.wday]} 開催 >\n\n" if index == 0
57-
event_info += "#{event.title}\n"
58-
event_info += "時間: #{event.start_at.strftime('%H:%M')}#{event.end_at.strftime('%H:%M')}\n"
59-
event_info += "詳細: #{Rails.application.routes.url_helpers.regular_event_url(event)}\n\n"
60-
is_outputted_event = true
61-
end
62-
end
63-
event_info += "------------------------------\n\n" if is_outputted_event
64-
end
65-
if tomorrow_events.present?
66-
tomorrow_events.each_with_index do |event, index|
67-
unless HolidayJp.holiday?(tomorrow) && !event.hold_national_holiday?
68-
event_info += "< 明日 (#{tomorrow.strftime('%m/%d')} #{day_of_the_week[tomorrow.wday]} 開催 >\n\n" if index == 0
69-
event_info += "#{event.title}\n"
70-
event_info += "時間: #{event.start_at.strftime('%H:%M')}#{event.end_at.strftime('%H:%M')}\n"
71-
event_info += "詳細: #{Rails.application.routes.url_helpers.regular_event_url(event)}\n\n"
72-
end
73-
end
74-
end
50+
event_info, is_outputted_event = add_event_info(today_events, '今日', today, event_info)
51+
event_info += "------------------------------\n\n" if is_outputted_event
52+
event_info = add_event_info(tomorrow_events, '明日', tomorrow, event_info)[0]
7553
event_info += '⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️'
7654

7755
notification(
@@ -80,7 +58,21 @@ def coming_soon_regular_events(params = {})
8058
webhook_url: webhook_url
8159
)
8260
end
83-
# rubocop:enable Metrics/MethodLength
61+
62+
def add_event_info(events, date_message, date, event_info)
63+
day_of_the_week = %w[ ]
64+
is_outputted_event = false
65+
events.each_with_index do |event, index|
66+
next if HolidayJp.holiday?(date) && !event.hold_national_holiday?
67+
68+
event_info += "< #{date_message} (#{date.strftime('%m/%d')} #{day_of_the_week[date.wday]} 開催 >\n\n" if index.zero?
69+
event_info += "#{event.title}\n"
70+
event_info += "時間: #{event.start_at.strftime('%H:%M')}#{event.end_at.strftime('%H:%M')}\n"
71+
event_info += "詳細: #{Rails.application.routes.url_helpers.regular_event_url(event)}\n\n"
72+
is_outputted_event = true
73+
end
74+
[event_info, is_outputted_event]
75+
end
8476

8577
def invalid_user(params = {})
8678
params.merge!(@params)

0 commit comments

Comments
 (0)