Class: Clasrip::DatesBetween

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start, finish) ⇒ DatesBetween

Returns a new instance of DatesBetween.



20
21
22
23
24
25
# File 'lib/clasrip.rb', line 20

def initialize(start, finish)
  @day = 0
  @year = start
  @finish = finish
  @month = 0
end

Instance Attribute Details

#dayObject

Returns the value of attribute day.



18
19
20
# File 'lib/clasrip.rb', line 18

def day
  @day
end

#monthObject

Returns the value of attribute month.



18
19
20
# File 'lib/clasrip.rb', line 18

def month
  @month
end

#yearObject

Returns the value of attribute year.



18
19
20
# File 'lib/clasrip.rb', line 18

def year
  @year
end

Instance Method Details

#eachObject



48
49
50
51
52
53
54
# File 'lib/clasrip.rb', line 48

def each
  loop do
    yield self.next
  end
rescue StopIteration
  self
end

#nextObject

Raises:

  • (StopIteration)


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/clasrip.rb', line 31

def next
  raise StopIteration if @year >= @finish
  if @day >= 1 and @day < 15
    @day = 15
  else 
    @month += 1
    @day = 1
  end
  
  if @month > 12
    @month = 1
    @year += 1
  end
  
  to_s 
end

#to_sObject



27
28
29
# File 'lib/clasrip.rb', line 27

def to_s
  "#{@day}/#{@month}/#{@year}"
end