File: season.rb

package info (click to toggle)
ruby-chronic 0.6.7-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 384 kB
  • sloc: ruby: 3,726; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 999 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Chronic
  class Season
    # @return [MiniDate]
    attr_reader :start

    # @return [MiniDate]
    attr_reader :end

    # @param [MiniDate] start_date
    # @param [MiniDate] end_date
    def initialize(start_date, end_date)
      @start = start_date
      @end = end_date
    end

    # @param [Symbol]  season  The season name
    # @param [Integer] pointer The direction (-1 for past, 1 for future)
    # @return [Symbol] The new season name
    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

    # @param [Symbol] season The season name
    # @return [Symbol] The new season name
    def self.season_after(season)
      find_next_season(season, +1)
    end

    # @param [Symbol] season The season name
    # @return [Symbol] The new season name
    def self.season_before(season)
      find_next_season(season, -1)
    end
  end
end