Class: TimerWithSnooze::Alert
- Inherits:
-
Object
- Object
- TimerWithSnooze::Alert
- Defined in:
- lib/timer_with_snooze.rb
Instance Attribute Summary collapse
-
#dd ⇒ Object
Returns the value of attribute dd.
-
#mm ⇒ Object
Returns the value of attribute mm.
-
#yr ⇒ Object
Returns the value of attribute yr.
Class Method Summary collapse
Instance Method Summary collapse
- #_setting ⇒ Object
- #add_alert(hour, min) ⇒ Object
-
#initialize(hour = 6, min = 15) ⇒ Alert
constructor
A new instance of Alert.
- #last_stop ⇒ Object
- #list_all_stops ⇒ Object
- #print_stops ⇒ Object
- #ring ⇒ Object
- #setting ⇒ Object
- #snooze ⇒ Object
Constructor Details
#initialize(hour = 6, min = 15) ⇒ Alert
Returns a new instance of Alert.
21 22 23 24 25 26 27 28 29 |
# File 'lib/timer_with_snooze.rb', line 21 def initialize(hour=6, min=15) @stops = [] tday = Alert.time_class.now yr = tday.year mn = tday.month dd = tday.day atime = [yr,mn,dd,hour,min,0] @stops << Time.new(*atime) end |
Instance Attribute Details
#dd ⇒ Object
Returns the value of attribute dd.
19 20 21 |
# File 'lib/timer_with_snooze.rb', line 19 def dd @dd end |
#mm ⇒ Object
Returns the value of attribute mm.
19 20 21 |
# File 'lib/timer_with_snooze.rb', line 19 def mm @mm end |
#yr ⇒ Object
Returns the value of attribute yr.
19 20 21 |
# File 'lib/timer_with_snooze.rb', line 19 def yr @yr end |
Class Method Details
.runtime_class ⇒ Object
77 78 79 |
# File 'lib/timer_with_snooze.rb', line 77 def self.runtime_class @runtime_class || Time end |
.time_class ⇒ Object
73 74 75 |
# File 'lib/timer_with_snooze.rb', line 73 def self.time_class @time_class || Time end |
Instance Method Details
#_setting ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/timer_with_snooze.rb', line 31 def _setting result = false until result hour = InputData.input_int_validation I18n.t("input_hour") result = hour.between?(0,23) if !result puts I18n.t("err_hour") end end result = false until result minute = InputData.input_int_validation I18n.t("input_minute") result = minute.between?(0,59) if !result puts I18n.t("err_minute") end end tday = Alert.time_class.now yr = tday.year mn = tday.month dd = tday.day time_arr = [yr,mn,dd,hour,minute,0] atime = Time.new(*time_arr) ans = InputData.input_str_validation("#{atime}" + I18n.t("add_this_time"), 'y') if ans @stops << atime end end |
#add_alert(hour, min) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/timer_with_snooze.rb', line 81 def add_alert(hour, min) tday = Alert.time_class.now yr = tday.year mn = tday.month dd = tday.day atime = [yr,mn,dd,hour,min,0] @stops << Time.new(*atime) end |
#last_stop ⇒ Object
91 92 93 |
# File 'lib/timer_with_snooze.rb', line 91 def last_stop @stops.last end |
#list_all_stops ⇒ Object
95 96 97 98 99 100 |
# File 'lib/timer_with_snooze.rb', line 95 def list_all_stops puts I18n.t("display_times") @stops.each do |stop| puts "#{stop}" end end |
#print_stops ⇒ Object
102 103 104 105 106 |
# File 'lib/timer_with_snooze.rb', line 102 def print_stops @stops.each_with_index do |at, inx| puts "#{at} [#{inx}]" end end |
#ring ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/timer_with_snooze.rb', line 108 def ring enum = @stops.to_enum loop do begin stoptime = enum.next puts "in begin #{stoptime}" snoozup = nil loop do Signal.trap(:INT){ if __method__ == :ring puts "SIGINT" exit(0) else puts "Snooze stopped\n" return true end } print "."; #puts Alert.runtime_class.now if !snoozup and Alert.runtime_class.now >= stoptime and Alert.runtime_class.now < stoptime + 60 * 15 puts "snooze started at #{stoptime}" snoozup = snooze end sleep 5 end rescue StopIteration => e puts "end of @stop" break end end end |
#setting ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/timer_with_snooze.rb', line 63 def setting result = true while result _setting result = InputData.input_str_validation(I18n.t("add_more_time"), 'y') end list_all_stops end |
#snooze ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/timer_with_snooze.rb', line 143 def snooze Signal.trap(:INT){ puts "Snooze stoped\n" #puts "#{__method__}\n" return true } 15.times do print "wake up! \a " sleep 2 end print "\n" return true end |