Method: Request::Choregraphy#initialize

Defined in:
lib/violet/request.rb

#initialize(h = Hash.new, &block) ⇒ Choregraphy

Take some Choregraphy DSL code and translate it into a Choregraphy description of Violet API.

Arguments

(optionals) an Hash in argument with keys:

name

the chortitle

code

an array of String/Proc or a String/Proc that describe the Choregraphy in our DSL.

(optionals) a block of code that describe the Choregraphy.

Raise

raise a Choregraphy::BadChorDesc if not happy.

Examples (all results are equals)

Request::Choregraphy.new { set all off; move right ear forward of degrees 180 } #   => #<Request::Choregraphy:0x2b07a05f8ca0 @chor=["0,led,0,0,0,0", "0,led,1,0,0,0", "0,led,2,0,0,0", "0,led,3,0,0,0", "0,led,4,0,0,0", "0,motor,0,180,0,0"], @code=[#<Proc:0x00002b07a05f8d40@(irb):3>], @time=0>
Request::Choregraphy.new :code => 'set all off; move right ear forward of degrees 180' #   => #<Request::Choregraphy:0x2b07a05e84b8 @chor=["0,led,0,0,0,0", "0,led,1,0,0,0", "0,led,2,0,0,0", "0,led,3,0,0,0", "0,led,4,0,0,0", "0,motor,0,180,0,0"], @code=["set all off; move right ear forward of degrees 180"], @time=0>
Request::Choregraphy.new :code => [ 'set all off', 'move right ear forward of degrees 180' ] #   => #<Request::Choregraphy:0x2b07a05dae30 @chor=["0,led,0,0,0,0", "0,led,1,0,0,0", "0,led,2,0,0,0", "0,led,3,0,0,0", "0,led,4,0,0,0", "0,motor,0,180,0,0"], @code=["set all off", "move right ear forward of degrees 180"], @time=0>


363
364
365
366
367
368
# File 'lib/violet/request.rb', line 363

def initialize(h=Hash.new, &block)
  @name = h[:name] if h[:name]
  @code = if block_given? then block else h[:code] end
  __choreval__
  @chor.sort! unless @chor.nil?
end