Class: Quixote

Inherits:
Object
  • Object
show all
Defined in:
lib/quixote.rb,
lib/quixote/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Quixote

Returns a new instance of Quixote.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/quixote.rb', line 9

def initialize(options={})
  defaults = {
    :max => 100,
    :min => 0,
    :range_by => 10
  }

  defaults.merge(options).each do |key, value|
    send("#{key}=", value)
  end

  @last = random_start_point
end

Instance Attribute Details

#lastObject

Returns the value of attribute last.



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

def last
  @last
end

#maxObject

Returns the value of attribute max.



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

def max
  @max
end

#minObject

Returns the value of attribute min.



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

def min
  @min
end

#range_byObject

Returns the value of attribute range_by.



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

def range_by
  @range_by
end

Instance Method Details

#nextObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/quixote.rb', line 23

def next
  if last == max
    decrement
  elsif last == min || (rand < 0.5)
    increment
  else
    decrement
  end
  last
end