Class: Lockfile::SleepCycle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min, max, inc) ⇒ SleepCycle

Returns a new instance of SleepCycle.

Raises:

  • (RangeError)


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lockfile.rb', line 32

def initialize(min, max, inc)
  @min, @max, @inc = Float(min), Float(max), Float(inc)
  @range = @max - @min
  raise RangeError, "max(#{ @max }) <= min(#{ @min })" if @max <= @min
  raise RangeError, "inc(#{ @inc }) > range(#{ @range })" if @inc > @range
  raise RangeError, "inc(#{ @inc }) <= 0" if @inc <= 0
  raise RangeError, "range(#{ @range }) <= 0" if @range <= 0
  s = @min
  push(s) and s += @inc while(s <= @max)
  self[-1] = @max if self[-1] < @max
  reset
end

Instance Attribute Details

#incObject (readonly)

Returns the value of attribute inc.



30
31
32
# File 'lib/lockfile.rb', line 30

def inc
  @inc
end

#maxObject (readonly)

Returns the value of attribute max.



28
29
30
# File 'lib/lockfile.rb', line 28

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



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

def min
  @min
end

#rangeObject (readonly)

Returns the value of attribute range.



29
30
31
# File 'lib/lockfile.rb', line 29

def range
  @range
end

Instance Method Details

#nextObject



45
46
47
48
49
# File 'lib/lockfile.rb', line 45

def next
  ret = self[@idx]
  @idx = ((@idx + 1) % self.size)
  ret
end

#resetObject



51
52
53
# File 'lib/lockfile.rb', line 51

def reset
  @idx = 0
end