class TimerWithSnooze::Alert

Attributes

dd[RW]
mm[RW]
yr[RW]

Public Class Methods

new(hour=6, min=15) click to toggle source
# 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
runtime_class() click to toggle source
# File lib/timer_with_snooze.rb, line 77
def self.runtime_class
  @runtime_class || Time
end
time_class() click to toggle source
# File lib/timer_with_snooze.rb, line 73
def self.time_class
  @time_class || Time
end

Public Instance Methods

_setting() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/timer_with_snooze.rb, line 91
def last_stop
  @stops.last
end
list_all_stops() click to toggle source
# 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() click to toggle source
ring() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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