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
# File 'lib/dateseq.rb', line 8

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

Instance Method Details

#sequence(from_date, to_date) ⇒ Object



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

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

#sequence_str(from_date, to_date) ⇒ Object



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

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