Class: SetPartition::Generator

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

Direct Known Subclasses

FixedGenerator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length) ⇒ Generator

Returns a new instance of Generator.



5
6
7
8
9
10
# File 'lib/set_partition/generator.rb', line 5

def initialize length
  @length = length
  initialize_first
  initialize_last
  start
end

Instance Attribute Details

#currentObject (readonly)

Returns the value of attribute current.



3
4
5
# File 'lib/set_partition/generator.rb', line 3

def current
  @current
end

Instance Method Details

#endObject



18
19
20
21
# File 'lib/set_partition/generator.rb', line 18

def end
  @current = @last.dup
  @maximum = @last.dup
end

#lengthObject



36
37
38
# File 'lib/set_partition/generator.rb', line 36

def length
  partition_length
end

#nextObject



23
24
25
26
27
# File 'lib/set_partition/generator.rb', line 23

def next
  return if @current == @last
  next_partition
  @current
end

#prevObject Also known as: previous



29
30
31
32
33
# File 'lib/set_partition/generator.rb', line 29

def prev
  return if @current == @first
  previous_partition
  @current
end

#startObject Also known as: rewind



12
13
14
15
# File 'lib/set_partition/generator.rb', line 12

def start
  @current = @first.dup
  @maximum = @first.dup
end