Class: Quixote

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

Constant Summary collapse

VERSION =
"0.2.0"

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
22
23
# File 'lib/quixote.rb', line 9

def initialize(options={})
  start = options.delete(:start)

  defaults = {
    max: 100,
    min: 0,
    range_by: 10
  }

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

  @last = start || 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

#progressObject

Returns the value of attribute progress.



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

def progress
  @progress
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



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/quixote.rb', line 25

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