Class: Cada::Stepper
- Inherits:
-
Object
- Object
- Cada::Stepper
- Defined in:
- lib/cada/stepper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(range, start_date, end_date, &block) ⇒ Stepper
constructor
A new instance of Stepper.
- #step ⇒ Object
Constructor Details
#initialize(range, start_date, end_date, &block) ⇒ Stepper
Returns a new instance of Stepper.
14 15 16 17 18 19 |
# File 'lib/cada/stepper.rb', line 14 def initialize(range, start_date, end_date, &block) @range = range @start_date = start_date @end_date = end_date @block = block end |
Class Method Details
.method_missing(method_name, *args, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/cada/stepper.rb', line 4 def self.method_missing(method_name, *args, &block) if 1.respond_to?(method_name) start_date, end_date = args self.new(method_name, start_date, end_date, &block).step else = '`meh` is not a valid range. Use `day`, `month`, `week`, etc' fail NoMethodError, end end |
Instance Method Details
#step ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/cada/stepper.rb', line 21 def step current_date = @start_date while current_date <= @end_date @block.call(current_date) current_date += 1.send(@range) end end |