Class: Checkups::IntervalChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/checkups/notification_timer.rb

Class Method Summary collapse

Class Method Details

.is_hour_at_day_interval?(daily_frequency, time = Time.now.utc) ⇒ Boolean

rubocop:disable Naming/PredicateName

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/checkups/notification_timer.rb', line 28

def self.is_hour_at_day_interval?(daily_frequency, time = Time.now.utc)
  frequency = word_to_number(daily_frequency) || 1
  hourly_interval = 24 / frequency
  time.utc.hour.divmod(hourly_interval)[1].zero?
end

.word_to_number(word) ⇒ Object

rubocop:enable Naming/PredicateName



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/checkups/notification_timer.rb', line 35

def self.word_to_number(word)
  case word
  when String
    {
      "two" => 2,
      "three" => 3,
      "four" => 4,
      "six" => 6,
      "eight" => 8,
    }[word]
  else
    word
  end
end