Class: Dateseq::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/dateseq.rb

Overview

Date Sequence generator

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Generator

Returns a new instance of Generator.



8
9
10
11
12
# File 'lib/dateseq.rb', line 8

def initialize(options)
  @format = options[:format] || '%Y%m%d'
  @sep = options[:sep] || "\n"
  @step = options[:step] || 1
end

Instance Method Details

#sequence(from_date, to_date) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/dateseq.rb', line 14

def sequence(from_date, to_date)
  from = Date.parse(from_date)
  to = Date.parse(to_date)
  from.step(to, @step).map do |date|
    date.strftime(@format)
  end
end

#sequence_str(from_date, to_date) ⇒ Object



22
23
24
# File 'lib/dateseq.rb', line 22

def sequence_str(from_date, to_date)
  sequence(from_date, to_date).join(@sep)
end