Module: Seasonal

Defined in:
lib/seasonal.rb,
lib/seasonal/version.rb

Constant Summary collapse

CA =
{winter: ["Apple", "Orange", "Avacado"], spring: ["Pear", "Bannana", "Lemon"], summer: ["Cherry", "Watermelon", "Nectarine"], fall: ["Pear", "Bannana", "Lemon"]}.freeze
TX =
{winter: ["Apple", "Orange", "Avacado"], spring: ["Pear", "Bannana", "Lemon"], summer: ["Cherry", "Orange", "Nectarine"], fall: ["Pear", "Bannana", "Lemon"]}.freeze
VERSION =
"0.4.0"

Instance Method Summary collapse

Instance Method Details

#get_season(date) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/seasonal.rb', line 14

def get_season(date)
  case
  when date.month <= 3
    :winter
  when date.month <= 6
    :spring
  when date.month <= 9
    :summer
  else
    :fall
  end
end

#in_season?(date, state) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
# File 'lib/seasonal.rb', line 7

def in_season?(date, state)
  season = get_season(date)
  state = string_to_constant(state)

  state[season].include? name
end

#string_to_constant(string) ⇒ Object



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

def string_to_constant(string)
  Seasonal.const_get(string)
end