Class: Dnotify::Notifier
- Inherits:
-
Object
- Object
- Dnotify::Notifier
- Defined in:
- lib/dnotify.rb
Constant Summary collapse
- DefaultNotification =
{:body => "Alarm", :summary => "Alarm", :timeout => 2.5, :icon_path => File.join(File.dirname(__FILE__),'../resources/clock.png') }
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize ⇒ Notifier
constructor
A new instance of Notifier.
- #notify(reminder) ⇒ Object
- #reminders ⇒ Object
- #run ⇒ Object
- #trigger?(reminder) ⇒ Boolean
Constructor Details
#initialize ⇒ Notifier
Returns a new instance of Notifier.
49 50 51 |
# File 'lib/dnotify.rb', line 49 def initialize ENV['DISPLAY'] = config[:display] end |
Instance Method Details
#config ⇒ Object
75 76 77 |
# File 'lib/dnotify.rb', line 75 def config @config ||= YAML::load_file(Setup::ConfigPath) end |
#notify(reminder) ⇒ Object
61 62 63 |
# File 'lib/dnotify.rb', line 61 def notify(reminder) Libnotify.show(DefaultNotification.merge(reminder)) end |
#reminders ⇒ Object
71 72 73 |
# File 'lib/dnotify.rb', line 71 def reminders config[:reminders] end |
#run ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/dnotify.rb', line 53 def run return unless Setup.check #check if a reminder aligns with the current time reminders.each do |reminder| notify(reminder) if trigger?(reminder) end end |
#trigger?(reminder) ⇒ Boolean
65 66 67 68 69 |
# File 'lib/dnotify.rb', line 65 def trigger?(reminder) reminder_time = Chronic.parse(reminder[:time], :context => :past) now = Time.now.floor reminder_time == now end |