Class: Climer::Timer
- Inherits:
-
Object
- Object
- Climer::Timer
- Defined in:
- lib/climer/timer.rb
Constant Summary collapse
- CARRIAGE_RETURN =
"\r"
Instance Attribute Summary collapse
-
#alert_time ⇒ Object
readonly
Returns the value of attribute alert_time.
Instance Method Summary collapse
- #countdown_string ⇒ Object
-
#initialize(duration, alert_name = 'Climer::Timer', notification = 'Timer expired!', urgency = :normal) ⇒ Timer
constructor
A new instance of Timer.
- #time_remaining ⇒ Object
Constructor Details
#initialize(duration, alert_name = 'Climer::Timer', notification = 'Timer expired!', urgency = :normal) ⇒ Timer
Returns a new instance of Timer.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/climer/timer.rb', line 29 def initialize(duration, alert_name = 'Climer::Timer', notification = 'Timer expired!', urgency = :normal) @alert_time = Time.now + duration puts "Alert set to activate at #{@alert_time.strftime('%l:%M %p on %B %e, %Y')}" print countdown_string countdown_update_interval = '1 second' job = Rufus::Scheduler.every countdown_update_interval do print "#{CARRIAGE_RETURN}#{countdown_string}" end Rufus::Scheduler.at @alert_time do Rufus::Scheduler.scheduler.unschedule( job.job_id ) sleep TimeDistribution::SmartDuration.parse(countdown_update_interval).total puts "\nALERT! #{notification}" Libnotify.show summary: alert_name, body: notification, urgency: urgency end end |
Instance Attribute Details
#alert_time ⇒ Object (readonly)
Returns the value of attribute alert_time.
26 27 28 |
# File 'lib/climer/timer.rb', line 26 def alert_time @alert_time end |
Instance Method Details
#countdown_string ⇒ Object
53 54 55 |
# File 'lib/climer/timer.rb', line 53 def countdown_string time_remaining.format('%h:%M:%S') end |
#time_remaining ⇒ Object
50 51 52 |
# File 'lib/climer/timer.rb', line 50 def time_remaining Duration.new(@alert_time - Time.now) end |