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(pool_size) ⇒ Object



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

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

.display(offset = 0) ⇒ Object



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

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

.normalize_message(m) ⇒ Object



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

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

#displayObject



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

def display
  Cline.out_stream.tap do |out|
    out.puts display_message

    out.flush if out.respond_to?(:flush)
  end

  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



35
36
37
# File 'lib/cline/notification.rb', line 35

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