Class: Request::SetEarsPosition

Inherits:
Base::Event show all
Defined in:
lib/violet/request.rb

Overview

SetEarsPosition events change your rabbit’s ears positions. you can set left ear position, or right ear position, or both.

Examples

SetEarsPosition.new :posleft => 12                 # => #<Request::SetEarsPosition:0x2ad0b2c79680 @h={:posleft=>12}>
SetEarsPosition.new :posright => 1                 # => #<Request::SetEarsPosition:0x2ad0b2c70260 @h={:posright=>1}>
SetEarsPosition.new :posright => 5, :posleft => 5  # => #<Request::SetEarsPosition:0x2ad0b2c5e330 @h={:posleft=>5, :posright=>5}>

Constant Summary collapse

MIN_POS =
0
MAX_POS =
16

Instance Method Summary collapse

Methods inherited from Base::Event

#+, #streamed?

Constructor Details

#initialize(h) ⇒ SetEarsPosition

take an hash in parameter, with :posright and/or :posleft keys. values should be between SetEarsPosition::MIN_POS and SetEarsPosition::MAX_POS.

Raises:

  • (ArgumentError)


152
153
154
155
156
157
# File 'lib/violet/request.rb', line 152

def initialize h
  @h = h.dup
  raise ArgumentError.new('at least :posright or :posleft must be set')             unless @h[:posleft] or @h[:posright]
  raise ArgumentError.new(":posright must be between #{MIN_POS} and #{MAX_POS}")    if @h[:posright] and not @h[:posright].to_i.between?(MIN_POS,MAX_POS)
  raise ArgumentError.new(":posleft  must be between #{MIN_POS} and #{MAX_POS}")    if @h[:posleft ] and not @h[:posleft ].to_i.between?(MIN_POS,MAX_POS)
end

Instance Method Details

#to_urlObject



159
160
161
162
163
164
# File 'lib/violet/request.rb', line 159

def to_url
  url = Array.new
  url << "posleft=#{@h[:posleft].to_i}"   if @h[:posleft]
  url << "posright=#{@h[:posright].to_i}" if @h[:posright]
  url.sort
end