class Upcoming::Factory
Public Class Methods
every(method, options = {})
click to toggle source
# File lib/upcoming/factory.rb, line 13 def self.every(method, options = {}) new(options).then_find_upcoming(method) end
new(options = {})
click to toggle source
# File lib/upcoming/factory.rb, line 8 def initialize(options = {}) @options = parse(options) @chain = [] end
Public Instance Methods
each() { |inject{ |date, generator| step}| ... }
click to toggle source
# 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)
click to toggle source
# File lib/upcoming/factory.rb, line 22 def then_find_preceding(method) @chain << create_generator(method, :preceding) self end
then_find_upcoming(method)
click to toggle source
# File lib/upcoming/factory.rb, line 17 def then_find_upcoming(method) @chain << create_generator(method, :upcoming) self end
Private Instance Methods
create_generator(name, direction)
click to toggle source
# File lib/upcoming/factory.rb, line 49 def create_generator(name, direction) class_name = name.to_s.classify + 'Generator' generator_class = Upcoming.const_get class_name generator_class.new(choose: direction) end
parse(options)
click to toggle source
# File lib/upcoming/factory.rb, line 39 def parse(options) options[:from] ||= Date.today if options[:from].is_a? String iso = options[:from] =~ /\d{4}-\d{2}-\d{2}/ raise ArgumentError, 'Please use ISO dates (YYYY-MM-DD) as those are not ambigious.' unless iso end options[:from] = options[:from].to_date if options[:from].respond_to? :to_date options end