Class: Seasonal::Calendar

Inherits:
Array
  • Object
show all
Defined in:
lib/seasonal.rb

Instance Method Summary collapse

Instance Method Details

#going_on(options = {}) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/seasonal.rb', line 95

def going_on(options={})
  options = { :at => Time.now, :payloads => true }.merge(options)
  if block_given?
    if options[:payloads]
      each { |event| yield event.payload if event.going_on?(options[:at]) }
    else
      each { |event| yield event if event.going_on?(options[:at]) }
    end
  else
    result = reject { |event| !event.going_on?(options[:at]) }
    if options[:payloads]
      if result.empty? and !options[:or_if_none].nil?
        result.push(options[:or_if_none])
      else
        result.collect { |e| e.payload }
      end
    else
      result
    end
  end
end