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.



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

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

Instance Attribute Details

#endObject (readonly)

Returns the value of attribute end.



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

def end
  @end
end

#startObject (readonly)

Returns the value of attribute start.



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

def start
  @start
end

Class Method Details

.find_next_season(season, pointer) ⇒ Object



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

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



18
19
20
# File 'lib/chronic/season.rb', line 18

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

.season_before(season) ⇒ Object



22
23
24
# File 'lib/chronic/season.rb', line 22

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