Class: PostIt::Notification

Inherits:
Object
  • Object
show all
Includes:
Methadone::CLILogging, Methadone::Main, Methadone::SH
Defined in:
lib/post-it.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Notification

Returns a new instance of Notification.



14
15
16
17
18
19
20
21
22
# File 'lib/post-it.rb', line 14

def initialize(options={})
	@title = options[:title] ? options[:title] : 'Post It'
	@subtitle = options[:subtitle] ? options[:subtitle] : nil
	
	# Raise an exception if the Sticky Notifications app was not found
	unless File.exists?('/Applications/Sticky Notifications.app')
		raise "Sticky Notifications.app does not seem to be installed"
	end
end

Instance Attribute Details

#subtitleObject

Returns the value of attribute subtitle.



12
13
14
# File 'lib/post-it.rb', line 12

def subtitle
  @subtitle
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/post-it.rb', line 11

def title
  @title
end

Instance Method Details

#prepare(message, options = {}) ⇒ Object



44
45
46
47
# File 'lib/post-it.rb', line 44

def prepare(message,options={})
	options[:prepare] = true
	self.send(message,options)						
end

#send(message, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/post-it.rb', line 26

def send(message,options={})
	# Setup the default arguments for the SN url
	title = options[:title] ? options[:title] : self.title
	subtitle = options[:subtitle] ? options[:subtitle] : self.subtitle
	method = options[:prepare] ? 'prepare' : 'note'
	
	# Build the URL scheme for sticky-notifications
	notifyurl = "sticky-notifications://#{method}?message=#{message}&title=#{title}"	  
	notifyurl += "&subtitle=#{subtitle}" if subtitle		

	# Via Methadone::SH (shell) run the open command to open the url. Raise an exception if there were errors
	begin
	 	sh "open '#{notifyurl}'"
	rescue Exception => e 
	 	raise e.message 
	end
end