Class: Datey::Interrogator

Inherits:
Object
  • Object
show all
Defined in:
lib/datey/interrogator.rb

Instance Method Summary collapse

Constructor Details

#initialize(date) ⇒ Interrogator

Returns a new instance of Interrogator.



6
7
8
9
# File 'lib/datey/interrogator.rb', line 6

def initialize(date)
  @date = date.to_date
  @today = Date.today
end

Instance Method Details

#future?Boolean

Is the time in the future

Returns:

  • (Boolean)


80
81
82
# File 'lib/datey/interrogator.rb', line 80

def future?
  @date > @today
end

#last_week?Boolean

Does the date exist in the full week prior to the current week

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/datey/interrogator.rb', line 35

def last_week?
  beginning_of_previous_week = beginning_of_current_week - 7
  @date >= beginning_of_previous_week && @date < beginning_of_previous_week + 7
end

#last_x_days?(days) ⇒ Boolean

Does the date occur in the last X days not including today?

Returns:

  • (Boolean)


43
44
45
# File 'lib/datey/interrogator.rb', line 43

def last_x_days?(days)
  @date >= (@today - days) && @date < @today
end

#next_week?Boolean

Does the date occur next week? Assuming the next Sunday is the start of the next week.

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/datey/interrogator.rb', line 65

def next_week?
  beginning_of_next_week = beginning_of_current_week + 7
  @date >= beginning_of_next_week && @date < beginning_of_next_week + 7
end

#next_x_days?(days) ⇒ Boolean

Does the date occur in the next X days not including today?

Returns:

  • (Boolean)


50
51
52
# File 'lib/datey/interrogator.rb', line 50

def next_x_days?(days)
  @date > @today && @date <= (@today + days)
end

#past?Boolean

Is the time in the past

Returns:

  • (Boolean)


73
74
75
# File 'lib/datey/interrogator.rb', line 73

def past?
  @date < @today
end

#this_week?Boolean

Does the date existing in this week.

Returns:

  • (Boolean)


57
58
59
# File 'lib/datey/interrogator.rb', line 57

def this_week?
  @date >= beginning_of_current_week && @date < beginning_of_current_week + 7
end

#today?Boolean

Does the time occur today?

Returns:

  • (Boolean)


14
15
16
# File 'lib/datey/interrogator.rb', line 14

def today?
  @date == @today
end

#tomorrow?Boolean

Does the time occur tomorrow?

Returns:

  • (Boolean)


21
22
23
# File 'lib/datey/interrogator.rb', line 21

def tomorrow?
  @date == (@today + 1)
end

#yesterday?Boolean

Does the time occur yesterday?

Returns:

  • (Boolean)


28
29
30
# File 'lib/datey/interrogator.rb', line 28

def yesterday?
  @date == (@today - 1)
end