Class: Upcoming::Factory

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/upcoming/factory.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Factory

Returns a new instance of Factory.



8
9
10
11
# File 'lib/upcoming/factory.rb', line 8

def initialize(options = {})
  @options = parse(options)
  @chain = []
end

Class Method Details

.every(method, options = {}) ⇒ Object



13
14
15
# File 'lib/upcoming/factory.rb', line 13

def self.every(method, options = {})
  new(options).then_find_upcoming(method)
end

Instance Method Details

#eachObject



27
28
29
30
31
32
33
34
35
# File 'lib/upcoming/factory.rb', line 27

def each
  from = @options[:from]
  while true do
    from += 1
    next_date = @chain.first.step(from)
    yield @chain[1..-1].inject(next_date) { |date, generator| generator.step(date) }
    from = next_date
  end
end

#then_find_preceding(method) ⇒ Object



22
23
24
25
# File 'lib/upcoming/factory.rb', line 22

def then_find_preceding(method)
  @chain << create_generator(method, :preceding)
  self
end

#then_find_upcoming(method) ⇒ Object



17
18
19
20
# File 'lib/upcoming/factory.rb', line 17

def then_find_upcoming(method)
  @chain << create_generator(method, :upcoming)
  self
end