Method: TimeCalc::Value#iterate
- Defined in:
- lib/time_calc/value.rb
#iterate(span, unit) {|Time/Date/DateTime| ... } ⇒ Value
Like #+, but allows conditional skipping of some periods. Increases value by ‘unit` at least `span` times, on each iteration checking with block provided if this point matches desired period; if it is not, it is skipped without increasing iterations counter. Useful for “business date/time” algorithms.
See TimeCalc#iterate for examples.
188 189 190 191 192 193 194 195 |
# File 'lib/time_calc/value.rb', line 188 def iterate(span, unit) block_given? or fail ArgumentError, 'No block given' Integer === span or fail ArgumentError, 'Only integer spans are supported' # rubocop:disable Style/CaseEquality Enumerator.produce(self) { |v| v.+((span <=> 0).nonzero? || 1, unit) } .lazy.select { |v| yield(v.internal) } .drop(span.abs).first end |