class SM

Dibnahs_Dogs::Activity Modeller::State Machine.rb - 
    $Release Version: 0.2 $
    $Revision: 1.1.1 $
    by mark ingram

– Run this file for TEST and example use for documentation tips and usage call the <classname>_Doc i.e. SM_Doc for specific function documentation call

Attributes

count[R]
state[R]

Public Class Methods

new() click to toggle source
# File lib/dibnahs_dogs.rb, line 12
def initialize
  @count = 0 #number of states in the machine
  @state = 0
end

Public Instance Methods

clear() click to toggle source
# File lib/dibnahs_dogs.rb, line 36
def clear
  @count = 0
  @state = 0
end
count=(states) click to toggle source
# File lib/dibnahs_dogs.rb, line 17
def count=(states) 
  if states > 0 then @count = states
    self.state = 1
  else
    puts "StateMachine.Count requires one or more states. To clear the states, use StateMachine.Clear."
  end
end
move(states) click to toggle source
# File lib/dibnahs_dogs.rb, line 40
def move(states)
  tmp = 0
  tmp = self.state + states
  if tmp < 1 then state = 1
  end
  if tmp > @count then tmp = @count
  end
  # puts " =8= count #{@count}\nstates #{states}\ntmp#{tmp} \nself.state #{self.state} \n =8="
  self.state = tmp
  puts self.state
end
setState(newstate) click to toggle source
# File lib/dibnahs_dogs.rb, line 33
def setState(newstate)
  self.state = newstate
end
state=(newstate) click to toggle source
# File lib/dibnahs_dogs.rb, line 24
def state=(newstate)
  if newstate < 1 then 
    puts "StateMachine.State cannot be set less than 1"
  elsif newstate > self.count then puts " StateMachine.State cannot be set greater than StateMachine.Count."
  elsif newstate > 0 and newstate <= self.count then
    @state = newstate
    setState(newstate)
  end
end