Class: Activity::CompactNotes

Inherits:
Object
  • Object
show all
Defined in:
app/services/activity/compact_notes.rb

Instance Method Summary collapse

Instance Method Details

#process(limit: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/services/activity/compact_notes.rb', line 3

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 "---"
    if new_note.present?
      puts "[#{activity.id}] : #{new_note}"
    end
    activity.update_columns(notes: new_note)
  end

end

#trim_notes(notes, id = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'app/services/activity/compact_notes.rb', line 18

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).map(&:presence).compact.map{|s| s[0] == '.' ? s[1..] : s}.join("<br>")
  new_note = new_note.split('.').join(".\n")
  new_note.squish.presence
end