Skip to content

Commit

Permalink
クラス名・メソッド名・変数名を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
a-terumoto-gs committed May 27, 2024
1 parent 49bcbba commit 3f065b1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
16 changes: 8 additions & 8 deletions app/models/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ def combine_special_regular_calendar(user)
private

def generate_calendar_str(user)
events_list = EventList.new
personal_events_list = events_list.fetch_events_list(user)
events_icalendar_str = IcalendarStr.new
calendar_str = events_icalendar_str.convert_events_to_ical(personal_events_list)
events = EventsFetcher.new
personal_events = events.fetch_events(user)
events_icalendar_str = EventsToIcalConverter.new
calendar_str = events_icalendar_str.convert_events_to_ical(personal_events)

calendar_to_ical = calendar_str.to_ical
calendar_to_ical.gsub(/END:VCALENDAR\r?\n?\z/, '')
end

def generate_regular_calendar_str(user)
regular_events_list = EventList.new
personal_regular_events_list = regular_events_list.fetch_regular_events_list(user)
regular_events_icalendar_str = IcalendarStr.new
regular_calendar_str = regular_events_icalendar_str.convert_regular_events_to_ical(personal_regular_events_list)
regular_events = EventsFetcher.new
personal_regular_events = regular_events.fetch_regular_events(user)
regular_events_icalendar_str = EventsToIcalConverter.new
regular_calendar_str = regular_events_icalendar_str.convert_regular_events_to_ical(personal_regular_events)

regular_calendar_to_ical = regular_calendar_str.to_ical
regular_calendar_to_ical.gsub(/\A(?:BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:icalendar-ruby\r\nCALSCALE:GREGORIAN\r\n)/, '')
Expand Down
28 changes: 14 additions & 14 deletions app/models/event_list.rb → app/models/events_fetcher.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
# frozen_string_literal: true

class EventList
def fetch_events_list(user)
participated_list = user.participations.pluck(:event_id)
upcoming_event_list = Event.where('start_at > ?', Date.current).pluck(:id)
class EventsFetcher
def fetch_events(user)
participated_events = user.participations.pluck(:event_id)
upcoming_events = Event.where('start_at > ?', Date.current).pluck(:id)

joined_events = Event.where(id: participated_list & upcoming_event_list)
upcoming_events = Event.where(id: upcoming_event_list).where.not(id: participated_list)
joined_events = Event.where(id: participated_events & upcoming_events)
upcoming_events = Event.where(id: upcoming_events).where.not(id: participated_events)
{
joined_events:,
upcoming_events:
}
end

def fetch_regular_events_list(user)
participated_list = user.regular_event_participations.pluck(:regular_event_id)
regular_events_list = []
RegularEvent.where(id: participated_list).where(finished: false).find_each do |event|
def fetch_regular_events(user)
participated_events = user.regular_event_participations.pluck(:regular_event_id)
regular_events = []
RegularEvent.where(id: participated_events).where(finished: false).find_each do |event|
event.regular_event_repeat_rules.each do |repeat_rule|
current_date = Time.zone.today

list_regular_event_for_year(event, repeat_rule, current_date, regular_events_list)
list_regular_event_for_year(event, repeat_rule, current_date, regular_events)
end
end
regular_events_list
regular_events
end

private

def list_regular_event_for_year(event, repeat_rule, current_date, regular_events_list)
def list_regular_event_for_year(event, repeat_rule, current_date, regular_events)
while current_date <= Time.zone.today + 1.year
if repeat_rule.frequency.zero?
day_of_the_week_symbol = DateAndTime::Calculations::DAYS_INTO_WEEK.key(repeat_rule.day_of_the_week)
Expand All @@ -39,7 +39,7 @@ def list_regular_event_for_year(event, repeat_rule, current_date, regular_event
event_date = event.possible_next_event_date(current_date, repeat_rule)
current_date = current_date.next_month.beginning_of_month
end
regular_events_list << { event_id: event.id, event_date: }
regular_events << { event_id: event.id, event_date: }
end
end
end
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# frozen_string_literal: true

class IcalendarStr
def convert_events_to_ical(events_list)
class EventsToIcalConverter
def convert_events_to_ical(events)
event_cal = Icalendar::Calendar.new

events_list[:joined_events].each do |event|
events[:joined_events].each do |event|
add_event_to_calendar(event_cal, event, true)
end

events_list[:upcoming_events].each do |event|
events[:upcoming_events].each do |event|
add_event_to_calendar(event_cal, event, false)
end
event_cal
end

def convert_regular_events_to_ical(regular_events_list)
def convert_regular_events_to_ical(regular_events)
regular_event_cal = Icalendar::Calendar.new

add_regular_event_to_calendar(regular_event_cal, regular_events_list)
add_regular_event_to_calendar(regular_event_cal, regular_events)
regular_event_cal
end

Expand All @@ -36,8 +36,8 @@ def add_event_to_calendar(event_cal, event, joined)
end
end

def add_regular_event_to_calendar(regular_event_cal, regular_events_list)
regular_events_list.each do |regular_event|
def add_regular_event_to_calendar(regular_event_cal, regular_events)
regular_events.each do |regular_event|
tzid = 'Asia/Tokyo'
event_date = Date.parse(regular_event[:event_date].to_s)
event = RegularEvent.find(regular_event[:event_id])
Expand Down

0 comments on commit 3f065b1

Please sign in to comment.