Class: Rubot::DSL::BehaviorFactoryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/rubot/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, args, &block) ⇒ BehaviorFactoryBuilder

Returns a new instance of BehaviorFactoryBuilder.



9
10
11
12
13
14
# File 'lib/rubot/dsl.rb', line 9

def initialize(name, args, &block)
  @name = name.to_sym
  @args = args
  @sensors = []
  self.instance_eval(&block)
end

Instance Method Details

#buildObject



39
40
41
# File 'lib/rubot/dsl.rb', line 39

def build
  BehaviorFactory.new(@name, @args, @fire, @sensors.uniq)
end

#fire(&block) ⇒ Object

Defines the block of code to run when this behavior fires.

behavior :do_stuff do
  fire do
    # Do stuff
  end
end


23
24
25
# File 'lib/rubot/dsl.rb', line 23

def fire(&block)
  @fire = block
end

#sensors(*sensors) ⇒ Object

Specifies sensors to make available to the fire block.

behavior :log_sonar do
  sensors :sonar
  fire do
    puts "Sonar is reading #{sonar.range(-70,70)}"
  end
end


35
36
37
# File 'lib/rubot/dsl.rb', line 35

def sensors(*sensors)
  @sensors += sensors.map(&:to_sym)
end