Class: Chronic::RepeaterDayName

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

Overview

:nodoc:

Constant Summary collapse

DAY_SECONDS =

(24 * 60 * 60)

86400

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) ⇒ RepeaterDayName

Returns a new instance of RepeaterDayName.


4
5
6
7
# File 'lib/chronic/repeaters/repeater_day_name.rb', line 4

def initialize(type)
  super
  @current_day_start = nil
end

Instance Method Details

#next(pointer) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/chronic/repeaters/repeater_day_name.rb', line 9

def next(pointer)
  super
  
  direction = pointer == :future ? 1 : -1
  
  if !@current_day_start
    @current_day_start = Time.construct(@now.year, @now.month, @now.day)
    @current_day_start += direction * DAY_SECONDS

    day_num = symbol_to_number(@type)
    
    while @current_day_start.wday != day_num
      @current_day_start += direction * DAY_SECONDS
    end
  else
    @current_day_start += direction * 7 * DAY_SECONDS
  end
  
  Chronic::Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
end

#this(pointer = :future) ⇒ Object


30
31
32
33
34
35
# File 'lib/chronic/repeaters/repeater_day_name.rb', line 30

def this(pointer = :future)
  super
  
  pointer = :future if pointer == :none
  self.next(pointer)
end

#to_sObject


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

def to_s
  super << '-dayname-' << @type.to_s
end

#widthObject


37
38
39
# File 'lib/chronic/repeaters/repeater_day_name.rb', line 37

def width
  DAY_SECONDS
end