Class: Remedy::Key
- Inherits:
-
Object
- Object
- Remedy::Key
- Defined in:
- lib/remedy/key.rb
Instance Method Summary collapse
- #==(key) ⇒ Object
- #===(object) ⇒ Object
- #control? ⇒ Boolean
- #control_c? ⇒ Boolean
- #enc ⇒ Object
- #eql?(key) ⇒ Boolean
- #glyph ⇒ Object
- #gremlin? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(character_sequence) ⇒ Key
constructor
A new instance of Key.
- #inspect ⇒ Object
- #known? ⇒ Boolean
- #name ⇒ Object
- #nonprintable? ⇒ Boolean
- #printable? ⇒ Boolean
- #punctuation? ⇒ Boolean
- #raw ⇒ Object
- #recognized? ⇒ Boolean
- #seq ⇒ Object
- #sequence? ⇒ Boolean
- #single? ⇒ Boolean
- #to_s ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(character_sequence) ⇒ Key
Returns a new instance of Key.
6 7 8 |
# File 'lib/remedy/key.rb', line 6 def initialize character_sequence @character_sequence = character_sequence end |
Instance Method Details
#==(key) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/remedy/key.rb', line 83 def == key if key.respond_to? :raw then key.raw == raw else "#{raw}" == "#{key}" end end |
#===(object) ⇒ Object
97 98 99 |
# File 'lib/remedy/key.rb', line 97 def === object "#{object}" =~ /#{to_s}/i end |
#control? ⇒ Boolean
38 39 40 |
# File 'lib/remedy/key.rb', line 38 def control? @control ||= !!Characters.control[seq] end |
#control_c? ⇒ Boolean
50 51 52 |
# File 'lib/remedy/key.rb', line 50 def control_c? @control_c ||= seq == Characters.control.key(:control_c) end |
#enc ⇒ Object
18 19 20 |
# File 'lib/remedy/key.rb', line 18 def enc seq.dump[1..-2] end |
#eql?(key) ⇒ Boolean
91 92 93 94 95 |
# File 'lib/remedy/key.rb', line 91 def eql? key if key.is_a? self.class then self == key end end |
#glyph ⇒ Object
26 27 28 |
# File 'lib/remedy/key.rb', line 26 def glyph @glyph ||= get_glyph end |
#gremlin? ⇒ Boolean
46 47 48 |
# File 'lib/remedy/key.rb', line 46 def gremlin? @gremlin ||= !!Characters.gremlins[name] end |
#hash ⇒ Object
101 102 103 |
# File 'lib/remedy/key.rb', line 101 def hash raw.hash end |
#inspect ⇒ Object
79 80 81 |
# File 'lib/remedy/key.rb', line 79 def inspect "<#{self.class} #{name.inspect} value:#{value} glyph:#{glyph}>" end |
#name ⇒ Object
22 23 24 |
# File 'lib/remedy/key.rb', line 22 def name @name ||= Characters[seq] || :unknown end |
#nonprintable? ⇒ Boolean
34 35 36 |
# File 'lib/remedy/key.rb', line 34 def nonprintable? @nonprintable ||= !!Characters.nonprintable[seq] end |
#printable? ⇒ Boolean
30 31 32 |
# File 'lib/remedy/key.rb', line 30 def printable? @printable ||= !!Characters.printable[seq] end |
#punctuation? ⇒ Boolean
42 43 44 |
# File 'lib/remedy/key.rb', line 42 def punctuation? @control ||= !!Characters.punctuation[seq] end |
#raw ⇒ Object
14 15 16 |
# File 'lib/remedy/key.rb', line 14 def raw seq end |
#recognized? ⇒ Boolean
54 55 56 |
# File 'lib/remedy/key.rb', line 54 def recognized? @recognized ||= name != :unknown end |
#seq ⇒ Object
10 11 12 |
# File 'lib/remedy/key.rb', line 10 def seq @character_sequence end |
#sequence? ⇒ Boolean
66 67 68 |
# File 'lib/remedy/key.rb', line 66 def sequence? @sequence ||= raw.length > 1 end |
#single? ⇒ Boolean
62 63 64 |
# File 'lib/remedy/key.rb', line 62 def single? @single ||= raw.length == 1 end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/remedy/key.rb', line 70 def to_s @to_s ||= known? ? name.to_s : enc end |
#value ⇒ Object
74 75 76 77 |
# File 'lib/remedy/key.rb', line 74 def value raw_value = raw.bytes.to_a.join(' ') single? ? raw_value : "(#{raw_value})" end |