Module: Plushie::Protocol::Parsers

Defined in:
lib/plushie/protocol/parsers.rb

Overview

Shared string-to-symbol parsers used by the decode layer.

These convert wire-format strings into Ruby symbols for pattern matching in user code.

Constant Summary collapse

MOUSE_BUTTONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Mouse button name mapping.

{
  "left" => :left, "right" => :right, "middle" => :middle,
  "back" => :back, "forward" => :forward
}.freeze

Class Method Summary collapse

Class Method Details

.parse_mouse_button(str) ⇒ Symbol, ...

Parse a mouse button string to a symbol.

Parameters:

  • str (String, nil)

    "left", "right", "middle", "back", "forward"

Returns:

  • (Symbol, String, nil)


23
24
25
26
# File 'lib/plushie/protocol/parsers.rb', line 23

def parse_mouse_button(str)
  return nil if str.nil?
  MOUSE_BUTTONS.fetch(str, str)
end

.parse_pane_action(str) ⇒ Symbol?

Parse a pane drag action string to a symbol.

Parameters:

  • str (String, nil)

    "picked", "dropped", "canceled"

Returns:

  • (Symbol, nil)


43
44
45
46
47
48
49
# File 'lib/plushie/protocol/parsers.rb', line 43

def parse_pane_action(str)
  case str
  when "picked" then :picked
  when "dropped" then :dropped
  when "canceled" then :canceled
  end
end

.parse_pane_region(str) ⇒ Symbol?

Parse a pane region/edge string to a symbol.

Parameters:

  • str (String, nil)

    "center", "top", "bottom", "left", "right"

Returns:

  • (Symbol, nil)


55
56
57
58
59
60
61
62
63
# File 'lib/plushie/protocol/parsers.rb', line 55

def parse_pane_region(str)
  case str
  when "center" then :center
  when "top" then :top
  when "bottom" then :bottom
  when "left" then :left
  when "right" then :right
  end
end

.parse_scroll_unit(str) ⇒ Symbol?

Parse a scroll unit string to a symbol.

Parameters:

  • str (String, nil)

    "line", "lines", "pixel", "pixels"

Returns:

  • (Symbol, nil)

    :line, :pixel, or nil



32
33
34
35
36
37
# File 'lib/plushie/protocol/parsers.rb', line 32

def parse_scroll_unit(str)
  case str
  when "line", "lines" then :line
  when "pixel", "pixels" then :pixel
  end
end