Class: Chronic::RepeaterQuarterName

Inherits:
RepeaterQuarter show all
Defined in:
lib/chronic/repeaters/repeater_quarter_name.rb

Overview

:nodoc:

Constant Summary collapse

QUARTERS =
{
  :q1 => 0,
  :q2 => 1,
  :q3 => 2,
  :q4 => 3
}

Constants inherited from RepeaterQuarter

Chronic::RepeaterQuarter::MONTHS_PER_QUARTER, Chronic::RepeaterQuarter::QUARTER_SECONDS

Instance Attribute Summary

Attributes inherited from Tag

#type, #width

Instance Method Summary collapse

Methods inherited from RepeaterQuarter

#offset, #to_s, #width

Methods inherited from Repeater

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

Methods inherited from Tag

#initialize, scan, #start=

Constructor Details

This class inherits a constructor from Chronic::Tag

Instance Method Details

#next(pointer) ⇒ Object



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

def next(pointer)
  unless @current_span
    @current_span = this(pointer)
  else
    year_offset = pointer == :future ? 1 : -1
    new_year = @current_span.begin.year + year_offset
    time_basis = Chronic.construct(new_year, @current_span.begin.month)
    @current_span = quarter(time_basis)
  end

  @current_span
end

#this(pointer = :future) ⇒ Object



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

def this(pointer = :future)
  current_quarter_index = quarter_index(@now.month)
  target_quarter_index = QUARTERS[type]

  year_basis_offset = case pointer
  when :past then current_quarter_index > target_quarter_index ? 0 : -1
  when :future then current_quarter_index < target_quarter_index ? 0 : 1
  else 0
  end

  year_basis = @now.year + year_basis_offset
  month_basis = (MONTHS_PER_QUARTER * target_quarter_index) + 1
  time_basis = Chronic.construct(year_basis, month_basis)

  @current_span = quarter(time_basis)
end