Class: Chronic::Season

Inherits:
Object
  • Object
show all
Defined in:
lib/chronic/season.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_date, end_date) ⇒ Season

Returns a new instance of Season.

Parameters:



11
12
13
14
# File 'lib/chronic/season.rb', line 11

def initialize(start_date, end_date)
  @start = start_date
  @end = end_date
end

Instance Attribute Details

#endMiniDate (readonly)

Returns:



7
8
9
# File 'lib/chronic/season.rb', line 7

def end
  @end
end

#startMiniDate (readonly)

Returns:



4
5
6
# File 'lib/chronic/season.rb', line 4

def start
  @start
end

Class Method Details

.find_next_season(season, pointer) ⇒ Symbol

Returns The new season name.

Parameters:

  • season (Symbol)

    The season name

  • pointer (Integer)

    The direction (-1 for past, 1 for future)

Returns:

  • (Symbol)

    The new season name



19
20
21
22
23
# File 'lib/chronic/season.rb', line 19

def self.find_next_season(season, pointer)
  lookup = [:spring, :summer, :autumn, :winter]
  next_season_num = (lookup.index(season) + 1 * pointer) % 4
  lookup[next_season_num]
end

.season_after(season) ⇒ Symbol

Returns The new season name.

Parameters:

  • season (Symbol)

    The season name

Returns:

  • (Symbol)

    The new season name



27
28
29
# File 'lib/chronic/season.rb', line 27

def self.season_after(season)
  find_next_season(season, +1)
end

.season_before(season) ⇒ Symbol

Returns The new season name.

Parameters:

  • season (Symbol)

    The season name

Returns:

  • (Symbol)

    The new season name



33
34
35
# File 'lib/chronic/season.rb', line 33

def self.season_before(season)
  find_next_season(season, -1)
end