Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pooza committed Feb 26, 2025
1 parent b404849 commit 8deebe5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
38 changes: 17 additions & 21 deletions app/lib/tomato_shrieker/source/icalendar_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def days
return self['/source/days'] || 3
end

def google?
return true if self['/source/google'].nil?
return self['/source/google']
end

def entries(&block)
return enum_for(__method__) unless block
ical.events
Expand Down Expand Up @@ -91,9 +96,18 @@ def create_entry(event)
location: fedi_sanitize(event.location),
all_day: event.dtstart.is_a?(Icalendar::Values::Date),
}
data = fix_duration(data)
data = fix_body(data)
data = fix_location(data)
data = fix_google_calendar_entry(data) if google?
return data
end

def fix_google_calendar_entry(data)
# Google Calendarで、終日予定の終了日が1日ずれる。
data[:end_date] -= 1.days if data[:all_day] && (data[:start_date] < data[:end_date])

lines = data[:body].split(/\r?\n/)
lines.reject! {|line| line.match?(/^Google Meet に参加:/)}
lines.reject! {|line| line.match?(/^Meet の詳細:/)}
data[:body] = lines.join("\n")
return data
end

Expand Down Expand Up @@ -124,24 +138,6 @@ def self.all(&block)

private

def fix_duration(data)
# Google Calendarで、終日予定の終了日が1日ずれる。
data[:end_date] -= 1.days if data[:all_day] && (data[:start_date] < data[:end_date])
return data
end

def fix_body(data)
lines = data[:body].split(/\r?\n/)
lines.reject! {|line| line.match?(/^Google Meet に参加:/)}
lines.reject! {|line| line.match?(/^Meet の詳細:/)}
data[:body] = lines.join("\n")
return data
end

def fix_location(data)
return data
end

def start_time_today
return Time.parse(Time.now.strftime('%Y/%m/%d 00:00:00'))
end
Expand Down
11 changes: 7 additions & 4 deletions test/icalendar_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@ def test_fedi_sanitize?
end
end

def test_create_entry_normal
def test_sanitize
source = %{<a href="https://shonenjumpplus.com/episode/17106371859967525169">https://shonenjumpplus.com/episode/17106371859967525169</a><br>感想には是非、以下のタグをどうぞ!<br>#勇者アバン_42話<br>#勇者アバン_11巻 (11巻2話目にあたります)<br><br>#delmulin #更新}
sanitized = %{https://shonenjumpplus.com/episode/17106371859967525169\n感想には是非、以下のタグをどうぞ!\n#勇者アバン_42話\n#勇者アバン_11巻 (11巻2話目にあたります)\n\n#delmulin #更新}

assert_equal(sanitized, source.sanitize)
end

def test_create_entry_googlemeet
source = %(無理はせず、スコアのある、蓄積開始後ほこらに備えましょう #頑張りましたで称号\n\n#DQW期限\n\nGoogle Meet に参加: https://meet.google.com/aaa-bbbc-ccc\n\nMeet の詳細: https://support.google.com/a/users/ans)
def test_fix_body
source = IcalendarSource.new({})
entry = source.fix_google_calendar_entry(
body: %(無理はせず、スコアのある、蓄積開始後ほこらに備えましょう #頑張りましたで称号\n\n#DQW期限\n\nGoogle Meet に参加: https://meet.google.com/aaa-bbbc-ccc\n\nMeet の詳細: https://support.google.com/a/users/ans),
)
sanitized = %(無理はせず、スコアのある、蓄積開始後ほこらに備えましょう #頑張りましたで称号\n\n#DQW期限)

assert_equal(sanitized, source.sanitize)
assert_equal(sanitized, entry[:body])
end

def test_create_entry_location
Expand Down

0 comments on commit 8deebe5

Please sign in to comment.