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_decades, 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.



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

def initialize(type)
	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 = DateTime.new(y=@now.year, m=@now.month, d=@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
	Chronic::Span.new(Chronic.time_class.local(@current_date.year, @current_date.month, @current_date.day),
			  Chronic.time_class.local(next_date.year, next_date.month, next_date.day))
end

#this(pointer = :future) ⇒ Object



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

def this(pointer = :future)
	super

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

#to_sObject



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

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

#widthObject



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

def width
	DAY_SECONDS
end