Class: Sheha::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/sheha/helper.rb

Constant Summary collapse

WEEK_DAYS =
Date.const_get(:DAYNAMES).map {|week_day| week_day.downcase}

Class Method Summary collapse

Class Method Details

.find_week_day_index(week_day) ⇒ Object



52
53
54
# File 'lib/sheha/helper.rb', line 52

def self.find_week_day_index(week_day)
  WEEK_DAYS.find_index(week_day) + 1
end

.valid_month?(month) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/sheha/helper.rb', line 36

def self.valid_month?(month)
  month >= 1 && month <= 12
end

.valid_month_day?(month_day) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/sheha/helper.rb', line 40

def self.valid_month_day?(month_day)
  month_day >= 1 && month_day <= 31
end

.valid_week_day?(week_day) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/sheha/helper.rb', line 44

def self.valid_week_day?(week_day)
  WEEK_DAYS.member? week_day
end

.validate_month(month) ⇒ Object



24
25
26
# File 'lib/sheha/helper.rb', line 24

def self.validate_month(month)
  raise Sheha::InvalidMonthError, "There is no #{month} month." unless valid_month? month
end

.validate_month_day(month_day) ⇒ Object



28
29
30
# File 'lib/sheha/helper.rb', line 28

def self.validate_month_day(month_day)
  raise Sheha::InvalidMonthDayError, "There is no #{month_day} day in a month." unless valid_month_day? month_day
end

.validate_week_day(week_day) ⇒ Object



32
33
34
# File 'lib/sheha/helper.rb', line 32

def self.validate_week_day(week_day)
  raise Sheha::InvalidWeekDayError, "There is no #{week_day} in a week." unless valid_week_day? week_day
end

.week_day_at(index) ⇒ Object



48
49
50
# File 'lib/sheha/helper.rb', line 48

def self.week_day_at(index)
  WEEK_DAYS[index - 1]
end