Class: Dnotify::Notifier

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeNotifier

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

#configObject



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

#remindersObject



71
72
73
# File 'lib/dnotify.rb', line 71

def reminders
  config[:reminders]
end

#runObject



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

Returns:

  • (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