Class: Chronic::RepeaterHour

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

Overview

:nodoc:

Constant Summary collapse

HOUR_SECONDS =

60 * 60

3600

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

Returns a new instance of RepeaterHour.



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

def initialize(type)
	super
	@current_hour_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
# File 'lib/chronic/repeaters/repeater_hour.rb', line 9

def next(pointer)
	super

	if !@current_hour_start
		case pointer
		when :future
			@current_hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour + 1)
		when :past
			@current_hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour - 1)
		end
	else
		direction = pointer == :future ? 1 : -1
		@current_hour_start += direction * HOUR_SECONDS
	end

	Chronic::Span.new(@current_hour_start, @current_hour_start + HOUR_SECONDS)
end

#offset(span, amount, pointer) ⇒ Object



45
46
47
48
49
# File 'lib/chronic/repeaters/repeater_hour.rb', line 45

def offset(span, amount, pointer)
	direction = pointer == :future ? 1 : -1
	p [span, amount, pointer] if Chronic.debug
	span + direction * amount * HOUR_SECONDS
end

#this(pointer = :future) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/chronic/repeaters/repeater_hour.rb', line 27

def this(pointer = :future)
	super

	case pointer
	when :future
		hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
		hour_end = Time.construct(@now.year, @now.month, @now.day, @now.hour + 1)
	when :past
		hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour)
		hour_end = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
	when :none
		hour_start = Time.construct(@now.year, @now.month, @now.day, @now.hour)
		hour_end = hour_start + HOUR_SECONDS
	end

	Chronic::Span.new(hour_start, hour_end)
end

#to_sObject



55
56
57
# File 'lib/chronic/repeaters/repeater_hour.rb', line 55

def to_s
	super << '-hour'
end

#widthObject



51
52
53
# File 'lib/chronic/repeaters/repeater_hour.rb', line 51

def width
	HOUR_SECONDS
end