Class: String

Inherits:
Object
  • Object
show all
Defined in:
ext/apex_ext/apex_src/examples/kbd_plugin.rb

Instance Method Summary collapse

Instance Method Details

#clarify_charactersObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'ext/apex_ext/apex_src/examples/kbd_plugin.rb', line 96

def clarify_characters
  unclear = {
    ',' => 'Comma (,)',
    '.' => 'Period (.)',
    ';' => 'Semicolon (;)',
    ':' => 'Colon (:)',
    '`' => 'Backtick (`)',
    '-' => 'Minus Sign (-)',
    '+' => 'Plus Sign (+)',
    '=' => 'Equals Sign (=)',
    '_' => 'Underscore (_)',
    '~' => 'Tilde (~)',
    '\\' => 'Backslash (\\)',
    '|' => 'Pipe (|)',
    '' => 'Left Arrow (←)',
    '' => 'Right Arrow (→)',
    '' => 'Up Arrow (↑)',
    '' => 'Down Arrow (↓)'
  }
  unclear.fetch(self, self)
end

#clean_comboObject



19
20
21
22
23
24
25
26
27
28
# File 'ext/apex_ext/apex_src/examples/kbd_plugin.rb', line 19

def clean_combo
  gsub!(/(?<=\S)-(?=\S)/, ' ')
  gsub!(/\b(comm(and)?|cmd|clover)\b/i, '@')
  gsub!(/\b(cont(rol)?|ctr?l)\b/i, '^')
  gsub!(/\b(opt(ion)?|alt)\b/i, '~')
  gsub!(/\bshift\b/i, '$')
  gsub!(/\b(func(tion)?|fn)\b/i, '*')
  gsub!(/\b(hyper)\b/i, '%')
  self
end

#clean_combo!Object



44
45
46
# File 'ext/apex_ext/apex_src/examples/kbd_plugin.rb', line 44

def clean_combo!
  replace clean_combo
end

#lower_to_upperObject



30
31
32
33
34
35
36
37
38
# File 'ext/apex_ext/apex_src/examples/kbd_plugin.rb', line 30

def lower_to_upper
  doubles = [
    [',', '<'], ['.', '>'], ['/', '?'], [';', ':'], ["'", '"'],
    ['[', '{'], [']', '}'], ['\\', '|'], ['-', '_'], ['=', '+']
  ]
  lowers = doubles.map { |d| d[0] }
  uppers = doubles.map { |d| d[1] }
  lowers.include?(self) ? uppers[lowers.index(self)] : self
end

#mod_to_ent(use_symbol) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'ext/apex_ext/apex_src/examples/kbd_plugin.rb', line 60

def mod_to_ent(use_symbol)
  entities = {
    '' => '&#8963;',
    '' => '&#8997;',
    '' => '&#8679;',
    '' => '&#8984;',
    'Fn' => 'Fn',
    'Hyper' => 'Hyper'
  }
  names = {
    '' => 'Control',
    '' => 'Option',
    '' => 'Shift',
    '' => 'Command',
    'Fn' => 'Function',
    'Hyper' => 'Hyper (Control+Option+Shift+Command)'
  }
  if entities.key?(self)
    use_symbol ? entities[self] : names[self]
  else
    self
  end
end

#mod_to_titleObject



84
85
86
87
88
89
90
91
92
93
94
# File 'ext/apex_ext/apex_src/examples/kbd_plugin.rb', line 84

def mod_to_title
  entities = {
    '' => 'Control',
    '' => 'Option',
    '' => 'Shift',
    '' => 'Command',
    'Fn' => 'Function',
    'Hyper' => 'Hyper (Control+Option+Shift+Command)'
  }
  entities.key?(self) ? entities[self] : self
end

#name_to_ent(use_symbol) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'ext/apex_ext/apex_src/examples/kbd_plugin.rb', line 118

def name_to_ent(use_symbol)
  k = case strip.downcase
      when /^f(\d{1,2})$/
        num = Regexp.last_match(1)
        ["F#{num}", "F#{num}", "F#{num} Key"]
      when /^apple$/
        ['Apple', '&#63743;', 'Apple menu']
      when /^tab$/
        ['', '&#8677;', 'Tab Key']
      when /^caps(lock)?$/
        ['Caps Lock', '&#8682;', 'Caps Lock Key']
      when /^eject$/
        ['Eject', '&#9167;', 'Eject Key']
      when /^return$/
        ['Return', '&#9166;', 'Return Key']
      when /^enter$/
        ['Enter', '&#8996;', 'Enter (Fn Return) Key']
      when /^(del(ete)?|back(space)?)$/
        ['Del', '&#9003;', 'Delete']
      when /^fwddel(ete)?$/
        ['Fwd Del', '&#8998;', 'Forward Delete (Fn Delete)']
      when /^(esc(ape)?)$/
        ['Esc', '&#9099;', 'Escape Key']
      when /^(right|rt)$/
        ['Right Arrow', '&#8594;', 'Right Arrow Key']
      when /^(left|lt)$/
        ['Left Arrow', '&#8592;', 'Left Arrow Key']
      when /^up$/
        ['Up Arrow', '&#8593;', 'Up Arrow Key']
      when /^(down|dn)$/
        ['Down Arrow', '&#8595;', 'Down Arrow Key']
      when /^p(age|g)up$/
        ['PgUp', '&#8670;', 'Page Up Key']
      when /^p(age|g)d(ow)?n$/
        ['PgDn', '&#8671;', 'Page Down Key']
      when /^home$/
        ['Home', '&#8598;', 'Home Key']
      when /^end$/
        ['End', '&#8600;', 'End Key']
      when /^semi(colon)$/
        ['Semicolon', ';', 'Semicolon']
      when /^(single([- ]?quote?)?|quote?)$/
        ['Single Quote', "'", 'Single Quote']
      when /^double([- ]?quote?)?$/
        ['Double Quote', '"', 'Double Quote']
      when /^click$/
        ['click', '<i class="fas fa-mouse-pointer"></i>', 'left click']
      when /^hyper/i
        ['Hyper', 'Hyper', 'Hyper (Control+Option+Shift+Command)']
      else
        [self, self, capitalize]
      end
  use_symbol ? [k[1], k[2]] : [k[0], k[2]]
end

#to_modObject



48
49
50
51
52
53
54
55
56
57
58
# File 'ext/apex_ext/apex_src/examples/kbd_plugin.rb', line 48

def to_mod
  characters = {
    '^' => '',
    '~' => '',
    '$' => '',
    '@' => '',
    '*' => 'Fn',
    '%' => 'Hyper'
  }
  characters.key?(self) ? characters[self] : self
end

#upper?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'ext/apex_ext/apex_src/examples/kbd_plugin.rb', line 40

def upper?
  %w(< > ? : " { } | ! @ # $ % ^ & * \( \) _ +).include?(self)
end