Class: Chronic::RepeaterDay

Inherits:
Repeater show all
Defined in:
lib/chronic/repeaters/repeater_day.rb

Overview

:nodoc:

Constant Summary collapse

DAY_SECONDS =

(24 * 60 * 60)

86_400

Instance Attribute Summary

Attributes inherited from Tag

#type

Instance Method Summary collapse

Methods inherited from Repeater

#<=>, scan, scan_for_day_names, scan_for_day_portions, scan_for_month_names, scan_for_season_names, scan_for_times, scan_for_units

Methods inherited from Tag

#start=

Constructor Details

#initialize(type, options = {}) ⇒ RepeaterDay

Returns a new instance of RepeaterDay.



5
6
7
8
# File 'lib/chronic/repeaters/repeater_day.rb', line 5

def initialize(type, options = {})
  super
  @current_day_start = nil
end

Instance Method Details

#next(pointer) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/chronic/repeaters/repeater_day.rb', line 10

def next(pointer)
  super

  unless @current_day_start
    @current_day_start = Chronic.time_class.local(@now.year, @now.month, @now.day)
  end

  direction = pointer == :future ? 1 : -1
  @current_day_start += direction * DAY_SECONDS

  Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
end

#offset(span, amount, pointer) ⇒ Object



41
42
43
44
# File 'lib/chronic/repeaters/repeater_day.rb', line 41

def offset(span, amount, pointer)
  direction = pointer == :future ? 1 : -1
  span + direction * amount * DAY_SECONDS
end

#this(pointer = :future) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/chronic/repeaters/repeater_day.rb', line 23

def this(pointer = :future)
  super

  case pointer
  when :future
    day_begin = Chronic.construct(@now.year, @now.month, @now.day, @now.hour)
    day_end = Chronic.construct(@now.year, @now.month, @now.day) + DAY_SECONDS
  when :past
    day_begin = Chronic.construct(@now.year, @now.month, @now.day)
    day_end = Chronic.construct(@now.year, @now.month, @now.day, @now.hour)
  when :none
    day_begin = Chronic.construct(@now.year, @now.month, @now.day)
    day_end = Chronic.construct(@now.year, @now.month, @now.day) + DAY_SECONDS
  end

  Span.new(day_begin, day_end)
end

#to_sObject



50
51
52
# File 'lib/chronic/repeaters/repeater_day.rb', line 50

def to_s
  super << '-day'
end

#widthObject



46
47
48
# File 'lib/chronic/repeaters/repeater_day.rb', line 46

def width
  DAY_SECONDS
end