Module: LucaSupport::Range

Defined in:
lib/luca_support/range.rb

Overview

Partial range operation

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

:nodoc:



7
8
9
# File 'lib/luca_support/range.rb', line 7

def self.included(klass) # :nodoc:
  klass.extend ClassMethods
end

Instance Method Details

#by_month(step = nil, from: nil, to: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/luca_support/range.rb', line 11

def by_month(step = nil, from: nil, to: nil)
  return enum_for(:by_month, step, from: from, to: to) unless block_given?

  from ||= @start_date
  to ||= @end_date
  self.class.term_by_month(from, to, step || 1).each do |date|
    @cursor_start = date
    @cursor_end = step.nil? ? date : [date.next_month(step - 1), to].min
    yield @cursor_start, @cursor_end
  end
end