Class: AIPP::AIRAC

Inherits:
Object show all
Defined in:
lib/aipp/airac.rb

Overview

AIRAC cycle date calculations

Examples:

airac = AIPP::AIRAC.new('2018-01-01')
airac.date        # => #<Date: 2017-12-07 ((2458095j,0s,0n),+0s,2299161j)>
airac.id          # => 1713
airac.next_date   # => #<Date: 2018-01-04 ((2458123j,0s,0n),+0s,2299161j)>
airac.next_id     # => 1801

Constant Summary collapse

ROOT_DATE =

First AIRAC date following the last cycle length modification

Date.parse('2015-06-25').freeze
DAYS_PER_CYCLE =

Length of one AIRAC cycle

28

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(any_date = nil) ⇒ AIRAC

Returns a new instance of AIRAC.

Parameters:

  • any_date (Date) (defaults to: nil)

    any date within the AIRAC cycle (default: today)


25
26
27
28
29
30
# File 'lib/aipp/airac.rb', line 25

def initialize(any_date = nil)
  any_date = any_date ? Date.parse(any_date.to_s) : Date.today
  fail(ArgumentError, "cannot calculate dates before #{ROOT_DATE}") if any_date < ROOT_DATE
  @date = date_for(any_date)
  @id = id_for(@date)
end

Instance Attribute Details

#dateDate (readonly)

Returns AIRAC effective on date.

Returns:

  • (Date)

    AIRAC effective on date


19
20
21
# File 'lib/aipp/airac.rb', line 19

def date
  @date
end

#idInteger (readonly)

Returns AIRAC cycle ID.

Returns:


22
23
24
# File 'lib/aipp/airac.rb', line 22

def id
  @id
end

Instance Method Details

#next_dateDate

Returns next AIRAC effective on date.

Returns:

  • (Date)

    next AIRAC effective on date


33
34
35
# File 'lib/aipp/airac.rb', line 33

def next_date
  date + DAYS_PER_CYCLE
end

#next_idInteger

Returns next AIRAC cycle ID.

Returns:

  • (Integer)

    next AIRAC cycle ID


38
39
40
# File 'lib/aipp/airac.rb', line 38

def next_id
  id_for next_date
end