Class: Uur::TimeMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/uur/time_mapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(now) ⇒ TimeMapper

Returns a new instance of TimeMapper.



4
5
6
# File 'lib/uur/time_mapper.rb', line 4

def initialize(now)
  @now = now
end

Instance Method Details

#since(time) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/uur/time_mapper.rb', line 8

def since(time)
  case time
  when "today"      then @now.beginning_of_day
  when "yesterday"  then @now.beginning_of_previous_day
  when "this-week"  then @now.beginning_of_week
  when "last-week"  then @now.beginning_of_previous_week
  when "this-month" then @now.beginning_of_month
  when "last-month" then @now.beginning_of_previous_month
  when "this-year"  then @now.beginning_of_year
  when "last-year"  then @now.beginning_of_previous_year
  end
end

#to(time) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/uur/time_mapper.rb', line 21

def to(time)
  case time
  when "today"      then @now.end_of_day
  when "yesterday"  then @now.end_of_previous_day
  when "this-week"  then @now.end_of_week
  when "last-week"  then @now.end_of_previous_week
  when "this-month" then @now.end_of_month
  when "last-month" then @now.end_of_previous_month
  when "this-year"  then @now.end_of_year
  when "last-year"  then @now.end_of_previous_year
  end
end