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, options = {}) ⇒ RepeaterDayName

Returns a new instance of RepeaterDayName.



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

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

Instance Method Details

#next(pointer) ⇒ Object



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

def next(pointer)
  super

  direction = pointer == :future ? 1 : -1

  unless @current_date
    @current_date = ::Date.new(@now.year, @now.month, @now.day)
    @current_date += direction

    day_num = symbol_to_number(@type)

    while @current_date.wday != day_num
      @current_date += direction
    end
  else
    @current_date += direction * 7
  end
  next_date = @current_date.succ
  Span.new(Chronic.construct(@current_date.year, @current_date.month, @current_date.day), Chronic.construct(next_date.year, next_date.month, next_date.day))
end

#this(pointer = :future) ⇒ Object



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

def this(pointer = :future)
  super

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

#to_sObject



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

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

#widthObject



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

def width
  DAY_SECONDS
end