Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- ext/apex_ext/apex_src/examples/kbd_plugin.rb
Instance Method Summary collapse
- #clarify_characters ⇒ Object
- #clean_combo ⇒ Object
- #clean_combo! ⇒ Object
- #lower_to_upper ⇒ Object
- #mod_to_ent(use_symbol) ⇒ Object
- #mod_to_title ⇒ Object
- #name_to_ent(use_symbol) ⇒ Object
- #to_mod ⇒ Object
- #upper? ⇒ Boolean
Instance Method Details
#clarify_characters ⇒ Object
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_combo ⇒ Object
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_upper ⇒ Object
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 = { '⌃' => '⌃', '⌥' => '⌥', '⇧' => '⇧', '⌘' => '⌘', '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_title ⇒ Object
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', '', 'Apple menu'] when /^tab$/ ['', '⇥', 'Tab Key'] when /^caps(lock)?$/ ['Caps Lock', '⇪', 'Caps Lock Key'] when /^eject$/ ['Eject', '⏏', 'Eject Key'] when /^return$/ ['Return', '⏎', 'Return Key'] when /^enter$/ ['Enter', '⌤', 'Enter (Fn Return) Key'] when /^(del(ete)?|back(space)?)$/ ['Del', '⌫', 'Delete'] when /^fwddel(ete)?$/ ['Fwd Del', '⌦', 'Forward Delete (Fn Delete)'] when /^(esc(ape)?)$/ ['Esc', '⎋', 'Escape Key'] when /^(right|rt)$/ ['Right Arrow', '→', 'Right Arrow Key'] when /^(left|lt)$/ ['Left Arrow', '←', 'Left Arrow Key'] when /^up$/ ['Up Arrow', '↑', 'Up Arrow Key'] when /^(down|dn)$/ ['Down Arrow', '↓', 'Down Arrow Key'] when /^p(age|g)up$/ ['PgUp', '⇞', 'Page Up Key'] when /^p(age|g)d(ow)?n$/ ['PgDn', '⇟', 'Page Down Key'] when /^home$/ ['Home', '↖', 'Home Key'] when /^end$/ ['End', '↘', '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_mod ⇒ Object
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
40 41 42 |
# File 'ext/apex_ext/apex_src/examples/kbd_plugin.rb', line 40 def upper? %w(< > ? : " { } | ! @ # $ % ^ & * \( \) _ +).include?(self) end |