Class: Hiccup::Inferable::DatesEnumerator

Inherits:
Object
  • Object
show all
Defined in:
lib/hiccup/inferable/dates_enumerator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dates) ⇒ DatesEnumerator

Returns a new instance of DatesEnumerator.



5
6
7
8
9
# File 'lib/hiccup/inferable/dates_enumerator.rb', line 5

def initialize(dates)
  @dates = dates
  @last_index = @dates.length - 1
  @index = -1
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



11
12
13
# File 'lib/hiccup/inferable/dates_enumerator.rb', line 11

def index
  @index
end

Instance Method Details

#done?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/hiccup/inferable/dates_enumerator.rb', line 13

def done?
  @index == @last_index
end

#nextObject

Raises:

  • (OutOfRangeException)


17
18
19
20
21
# File 'lib/hiccup/inferable/dates_enumerator.rb', line 17

def next
  @index += 1
  raise OutOfRangeException if @index > @last_index
  @dates[@index]
end

#rewind_by(n) ⇒ Object



23
24
25
26
# File 'lib/hiccup/inferable/dates_enumerator.rb', line 23

def rewind_by(n)
  @index -= n
  @index = -1 if @index < -1
end