Class: RPiet::CodelChooser

Inherits:
Object
  • Object
show all
Defined in:
lib/rpiet/codel_chooser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCodelChooser

Returns a new instance of CodelChooser.



7
# File 'lib/rpiet/codel_chooser.rb', line 7

def initialize; @direction = LEFT; end

Instance Attribute Details

#directionObject (readonly)

Returns the value of attribute direction.



6
7
8
# File 'lib/rpiet/codel_chooser.rb', line 6

def direction
  @direction
end

Instance Method Details

#ascii(dp) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rpiet/codel_chooser.rb', line 10

def ascii(dp)
  case dp.direction
  when RPiet::Direction::RIGHT
    @direction == LEFT ? "^" : "v"
  when RPiet::Direction::UP
    @direction == LEFT ? "<" : ">"
  when RPiet::Direction::LEFT
    @direction == LEFT ? "v" : "^"
  when RPiet::Direction::DOWN
    @direction == LEFT ? ">" : "<"
  end
end

#inspectObject Also known as: to_s



23
24
25
# File 'lib/rpiet/codel_chooser.rb', line 23

def inspect
  (@direction == LEFT ? "left(0)" : "right(1)")
end

#switch!(amount = 1) ⇒ Object



8
# File 'lib/rpiet/codel_chooser.rb', line 8

def switch!(amount = 1); @direction *= -1.**(amount % 2); end