Class: Spacy::Key

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/spacy/key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, shift = false, ctrl = false, alt = false) ⇒ Key

Returns a new instance of Key.



13
14
15
# File 'lib/spacy/key.rb', line 13

def initialize (key, shift = false, ctrl = false, alt = false)
  @key, @shift, @ctrl, @alt = key.to_sym, shift, ctrl, alt
end

Instance Attribute Details

#altObject (readonly)

Returns the value of attribute alt.



11
12
13
# File 'lib/spacy/key.rb', line 11

def alt
  @alt
end

#ctrlObject (readonly)

Returns the value of attribute ctrl.



11
12
13
# File 'lib/spacy/key.rb', line 11

def ctrl
  @ctrl
end

#keyObject (readonly)

Returns the value of attribute key.



11
12
13
# File 'lib/spacy/key.rb', line 11

def key
  @key
end

#shiftObject (readonly)

Returns the value of attribute shift.



11
12
13
# File 'lib/spacy/key.rb', line 11

def shift
  @shift
end

Instance Method Details

#<<(key) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
# File 'lib/spacy/key.rb', line 25

def << (key)
  raise ArgumentError unless key.kind_of? Key
  KeyStroke.new << self << key
end

#<=>(obj) ⇒ Object



38
39
40
# File 'lib/spacy/key.rb', line 38

def <=> (obj)
  to_s <=> obj.to_s
end

#eql?(obj) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/spacy/key.rb', line 34

def eql? (obj)
  to_s == obj.to_s
end

#hashObject



30
31
32
# File 'lib/spacy/key.rb', line 30

def hash ()
  to_s.hash
end

#inspectObject



42
43
44
45
46
47
48
# File 'lib/spacy/key.rb', line 42

def inspect ()
  mods = ''
  mods << ', shift' if @shift
  mods << ', ctrl'  if @ctrl
  mods << ', alt'   if @alt
  "#<Spacy::Key '#{@key.to_s}#{mods}'>"
end

#to_sObject



17
18
19
20
21
22
23
# File 'lib/spacy/key.rb', line 17

def to_s ()
  s = ''
  s << '/' if @alt
  s << '^' if @ctrl
  s << @key
  s
end