Class: QuoraNotify::Notification
- Inherits:
-
Object
- Object
- QuoraNotify::Notification
- Defined in:
- lib/quora_notify/notification.rb
Constant Summary collapse
- NOTIFICATION_GROUP =
'com.joeycarmello.quora_notify'
- NOTIFICATION_TITLE =
'New Notification'
Instance Attribute Summary collapse
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#hash ⇒ Object
Allows for fun things like [a, b] - [a] = [b].
- #id ⇒ Object
-
#initialize(notif) ⇒ Notification
constructor
A new instance of Notification.
- #notify ⇒ Object
Constructor Details
#initialize(notif) ⇒ Notification
Returns a new instance of Notification.
36 37 38 39 |
# File 'lib/quora_notify/notification.rb', line 36 def initialize(notif) @text = self.class.cleanse_text(notif) @links = notif.scan(/href="(.*?)"/).flatten end |
Instance Attribute Details
#links ⇒ Object (readonly)
Returns the value of attribute links.
25 26 27 |
# File 'lib/quora_notify/notification.rb', line 25 def links @links end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
25 26 27 |
# File 'lib/quora_notify/notification.rb', line 25 def text @text end |
Class Method Details
.cleanse_text(text) ⇒ Object
19 20 21 22 |
# File 'lib/quora_notify/notification.rb', line 19 def cleanse_text(text) coder = HTMLEntities.new coder.decode text.gsub(/<.*?>/, '') end |
.clear! ⇒ Object
14 15 16 17 |
# File 'lib/quora_notify/notification.rb', line 14 def clear! list.each { |notif| TerminalNotifier.remove(notif[:group]) } list.size end |
.list ⇒ Object
9 10 11 12 |
# File 'lib/quora_notify/notification.rb', line 9 def list notifs = TerminalNotifier.list('ALL') || [] notifs.select { |n| n[:group] =~ /^#{NOTIFICATION_GROUP}/ } end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
45 46 47 |
# File 'lib/quora_notify/notification.rb', line 45 def ==(other) other.kind_of?(QuoraNotify::Notification) ? id == other.id : other == id end |
#hash ⇒ Object
Allows for fun things like [a, b] - [a] = [b]
32 33 34 |
# File 'lib/quora_notify/notification.rb', line 32 def hash self.id.hash end |
#id ⇒ Object
27 28 29 |
# File 'lib/quora_notify/notification.rb', line 27 def id "#{NOTIFICATION_GROUP} - #{@text}" end |
#notify ⇒ Object
41 42 43 |
# File 'lib/quora_notify/notification.rb', line 41 def notify TerminalNotifier.notify(@text, :title => NOTIFICATION_TITLE, :open => @links.last, :group => self.id) end |