Class: Activity::CompactNotes
- Inherits:
-
Object
- Object
- Activity::CompactNotes
- Defined in:
- app/services/activity/compact_notes.rb
Overview
Service object: compact notes.
Instance Method Summary collapse
-
#process(limit: nil) ⇒ void
Strips the repeated "Time lock was overdue" boilerplate from activity notes.
-
#trim_notes(notes, _id = nil) ⇒ String?
Removes the boilerplate sentences and compacts whitespace in a note body.
Instance Method Details
#process(limit: nil) ⇒ void
This method returns an undefined value.
Strips the repeated "Time lock was overdue" boilerplate from activity notes.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/services/activity/compact_notes.rb', line 7 def process(limit: nil) activities ||= Activity.where("notes like '%Time lock was overdue%'") activities = activities.limit(limit) if limit activities.find_each do |activity| new_note = trim_notes(activity.notes, activity.id) # puts "#{activity.notes}" # puts "---" puts "[#{activity.id}] : #{new_note}" if new_note.present? activity.update_columns(notes: new_note) end end |
#trim_notes(notes, _id = nil) ⇒ String?
Removes the boilerplate sentences and compacts whitespace in a note body.
23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/activity/compact_notes.rb', line 23 def trim_notes(notes, _id = nil) html_note = Nokogiri::HTML(notes) new_note = html_note.text new_note = new_note.gsub(/\[.*\]\s*Time lock was overdue and moved to next working day for assigned employee/, '') new_note = new_note.squeeze(' ') new_note = new_note.squeeze('.') new_note = new_note.split(/(\[.*\])(\S*)/).map(&:strip).filter_map(&:presence).map { |s| s[0] == '.' ? s[1..] : s }.join("<br>") new_note = new_note.split('.').join(".\n") new_note.squish.presence end |