Class: Diter
Overview
Diter
enumerate dates with some filters.
require 'diter'
from = Date.new(2016, 1, 1)
to = Date.new(2016, 1, 31)
Diter[from, to, wday: 3].each do |date|
puts date.strftime('%Y/%m/%d')
end
#=>
# 2016/01/06
# 2016/01/13
# 2016/01/20
# 2016/01/27
Instance Method Summary collapse
-
#each {|date| ... } ⇒ Diter
Calls the given block once for each date.
-
#initialize(from, to, options = {}) ⇒ Diter
constructor
Return a new instance of
Diter
.
Constructor Details
#initialize(from, to, options = {}) ⇒ Diter
Return a new instance of Diter
.
If from
is greater than to
, it enumerate dates in reverse order.
38 39 40 41 |
# File 'bin/diter', line 38 def initialize(from, to, = {}) @range = from < to ? from..to : (to..from).reverse_each @options = end |
Instance Method Details
#each {|date| ... } ⇒ Diter
Calls the given block once for each date.
Return self
if no block is given.
49 50 51 52 53 54 55 56 57 58 |
# File 'bin/diter', line 49 def each return self unless block_given? @range.each do |date| next unless filter_wday(date) next unless filter_mday(date) yield date end end |