Sha256: 560712734da8912f49746c8c049133ec9d093e53bb9f8314d0bb4779ed5c134a

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

require "post-it/version"
require 'optparse'
require 'methadone'

module PostIt
	class Notification
		include Methadone::Main
		include Methadone::CLILogging
		include Methadone::SH

		attr_accessor :title
		attr_accessor :subtitle

		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
		
	public 
		
		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
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
post-it-1.0.2 lib/post-it.rb
post-it-1.0.1 lib/post-it.rb