Class: Remedy::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/remedy/key.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


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

def control?
  @control ||= !!Characters.control[seq]
end

#control_c?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/remedy/key.rb', line 50

def control_c?
  @control_c ||= seq == Characters.control.key(:control_c)
end

#encObject



18
19
20
# File 'lib/remedy/key.rb', line 18

def enc
  seq.dump[1..-2]
end

#eql?(key) ⇒ Boolean

Returns:

  • (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

#glyphObject



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

def glyph
  @glyph ||= get_glyph
end

#gremlin?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/remedy/key.rb', line 46

def gremlin?
  @gremlin ||= !!Characters.gremlins[name]
end

#hashObject



101
102
103
# File 'lib/remedy/key.rb', line 101

def hash
  raw.hash
end

#inspectObject



79
80
81
# File 'lib/remedy/key.rb', line 79

def inspect
  "<#{self.class} #{name.inspect} value:#{value} glyph:#{glyph}>"
end

#known?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/remedy/key.rb', line 58

def known?
  !!Characters[seq]
end

#nameObject



22
23
24
# File 'lib/remedy/key.rb', line 22

def name
  @name ||= Characters[seq] || :unknown
end

#nonprintable?Boolean

Returns:

  • (Boolean)


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

def nonprintable?
  @nonprintable ||= !!Characters.nonprintable[seq]
end

#printable?Boolean

Returns:

  • (Boolean)


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

def printable?
  @printable ||= !!Characters.printable[seq]
end

#punctuation?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/remedy/key.rb', line 42

def punctuation?
  @control ||= !!Characters.punctuation[seq]
end

#rawObject



14
15
16
# File 'lib/remedy/key.rb', line 14

def raw
  seq
end

#recognized?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/remedy/key.rb', line 54

def recognized?
  @recognized ||= name != :unknown
end

#seqObject



10
11
12
# File 'lib/remedy/key.rb', line 10

def seq
  @character_sequence
end

#sequence?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/remedy/key.rb', line 66

def sequence?
  @sequence ||= raw.length > 1
end

#single?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/remedy/key.rb', line 62

def single?
  @single ||= raw.length == 1
end

#to_sObject



70
71
72
# File 'lib/remedy/key.rb', line 70

def to_s
  @to_s ||= known? ? name.to_s : enc
end

#valueObject



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