Class: Cline::Notification

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/cline/notification.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clean(limit) ⇒ Object



52
53
54
55
56
57
# File 'lib/cline/notification.rb', line 52

def clean(limit)
  order('notified_at DESC').
    order(:display_count).
    offset(limit).
    destroy_all
end

.display!(offset = 0) ⇒ Object



44
45
46
# File 'lib/cline/notification.rb', line 44

def display!(offset = 0)
  earliest(1, offset).first.display!
end

.normalize_message(m) ⇒ Object



48
49
50
# File 'lib/cline/notification.rb', line 48

def normalize_message(m)
  m.gsub(/[\r\n]/, '')
end

Instance Method Details

#detect_url(protocols = %w(http https))) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/cline/notification.rb', line 72

def detect_url(protocols = %w(http https))
  regexp = URI.regexp(protocols)

  if match = message.match(regexp)
    match.to_s
  else
    nil
  end
end

#display!Object



60
61
62
63
64
# File 'lib/cline/notification.rb', line 60

def display!
  display_message.tap {
    increment! :display_count
  }
end

#display_messageObject



66
67
68
69
70
# File 'lib/cline/notification.rb', line 66

def display_message
  display_time = notified_at.strftime('%Y/%m/%d %H:%M')

  "[#{display_time}][#{display_count}][#{id_alias_string}] #{message}"
end

#id_alias_stringObject



82
83
84
# File 'lib/cline/notification.rb', line 82

def id_alias_string
  id_alias.to_i.to_s(36)
end

#message=(m) ⇒ Object



39
40
41
# File 'lib/cline/notification.rb', line 39

def message=(m)
  super Notification.normalize_message(m)
end