Class: Helene::SleepCycle

Inherits:
Array show all
Defined in:
lib/helene/sleepcycle.rb

Constant Summary collapse

Min =
0.01
Max =
1.28

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ SleepCycle

Returns a new instance of SleepCycle.



10
11
12
13
14
15
16
17
# File 'lib/helene/sleepcycle.rb', line 10

def initialize(*args)
  options = args.extract_options!.to_options!
  @min = options[:min] || Min
  @max = options[:max] || Max
  m = @min
  while m < @max; push(m) and m *= 2; end
  @pos = 0
end

Instance Attribute Details

#maxObject

Returns the value of attribute max.



7
8
9
# File 'lib/helene/sleepcycle.rb', line 7

def max
  @max
end

#minObject

Returns the value of attribute min.



6
7
8
# File 'lib/helene/sleepcycle.rb', line 6

def min
  @min
end

#posObject

Returns the value of attribute pos.



8
9
10
# File 'lib/helene/sleepcycle.rb', line 8

def pos
  @pos
end

Instance Method Details

#nextObject



19
20
21
22
23
# File 'lib/helene/sleepcycle.rb', line 19

def next
  self[@pos]
ensure
  @pos = ((@pos + 1) % size)
end

#resetObject



25
26
27
# File 'lib/helene/sleepcycle.rb', line 25

def reset
  @pos = 0
end