Module: Remedy::Characters

Defined in:
lib/remedy/characters.rb

Class Method Summary collapse

Class Method Details

.[](sequence_to_match) ⇒ Object



5
6
7
# File 'lib/remedy/characters.rb', line 5

def [] sequence_to_match
  all[sequence_to_match]
end

.allObject

Character Groups



11
12
13
# File 'lib/remedy/characters.rb', line 11

def all
  @all ||= printable.merge(nonprintable)
end

.alphabeticalObject



25
26
27
# File 'lib/remedy/characters.rb', line 25

def alphabetical
  @alphabetics ||= get_alphabetics
end

.alternate_namesObject



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/remedy/characters.rb', line 153

def alternate_names
  {
    control_a: :start_of_heading,
    control_b: :start_of_text,
    control_c: :end_of_transmission,
    control_d: :end_of_text,
    control_e: :enquiry,
    control_f: :acknowledge,
    control_g: :bel,
    control_h: :backspace,
    control_i: :horizontal_tabulation,
    control_j: :line_feed,
    control_k: :vertical_tabulation,
    control_l: :form_feed,
    control_m: :carriage_return,
    control_n: :shift_out,
    control_o: :shift_in,
    control_p: :data_link_escape,
    control_q: :device_control_one,
    control_r: :device_control_two,
    control_s: :device_control_three,
    control_t: :device_control_four,
    control_u: :negative_acknowledge,
    control_v: :sychnronous_idle,
    control_w: :end_of_transmission_block,
    control_x: :cancel,
    control_y: :end_of_medium,
    control_z: :substitute,

    control_left_square_bracket:  :escape,
    control_backslash:            :file_separator,
    control_right_square_bracket: :group_separator,
    control_caret:                :record_separator,
    control_underscore:           :unit_separator
  }
end

.controlObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/remedy/characters.rb', line 111

def control
  control_chars = {
    27.chr => :control_left_square_bracket,
    28.chr => :control_backslash,
    29.chr => :control_right_square_bracket,
    30.chr => :control_caret,
    31.chr => :control_underscore,
    127.chr => :delete,
    177.chr => :backspace
  }
  (?a..?z).each.with_index do |letter, index|
    control_chars.merge!({(index + 1).chr => "control_#{letter}".to_sym})
  end

  control_chars
end

.directionalObject



94
95
96
97
98
99
100
101
# File 'lib/remedy/characters.rb', line 94

def directional
  @directional ||= {
    "\e[A" => :up,
    "\e[B" => :down,
    "\e[D" => :left,
    "\e[C" => :right
  }
end

.escapeObject



103
104
105
106
107
108
109
# File 'lib/remedy/characters.rb', line 103

def escape
  @escape ||= {
    "\e" => :escape,

    "\e[3~" => :delete
  }
end

.get_alphabeticsObject



190
191
192
193
194
195
196
# File 'lib/remedy/characters.rb', line 190

def get_alphabetics
  letters = ('a'..'z').to_a + ('A'..'Z').to_a
  letters.inject(Hash.new) do |alphas, letter|
    alphas[letter] = letter.to_sym
    alphas
  end
end

.gremlinsObject

Glyphs and Alternate Names



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/remedy/characters.rb', line 130

def gremlins
  {
    space:           "\u2420",
    tab:             "\u21B9",
    carriage_return: "\u23CE",
    line_feed:       "\u240A",

    control_c: "\u2404",
    control_d: "\u2403",
    control_r: "\u2412",

    escape: "\u238B",

    backspace: "\u2408",
    delete:    "\u232B",

    up:    "\u2191",
    down:  "\u2193",
    left:  "\u2190",
    right: "\u2192"
  }
end

.nonprintableObject



29
30
31
# File 'lib/remedy/characters.rb', line 29

def nonprintable
  @nonprintable ||= special.merge(directional).merge(escape).merge(control)
end

.numericObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/remedy/characters.rb', line 42

def numeric
  @numeric ||= {
    ?0 => :zero,
    ?1 => :one,
    ?2 => :two,
    ?3 => :three,
    ?4 => :four,
    ?5 => :five,
    ?6 => :six,
    ?7 => :seven,
    ?8 => :eight,
    ?9 => :nine
  }
end

.printableObject



15
16
17
18
19
20
21
22
23
# File 'lib/remedy/characters.rb', line 15

def printable
  @printable ||= whitespace.merge(
    alphabetical.merge(
      numeric.merge(
        punctuation
      )
    )
  )
end

.punctuationObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/remedy/characters.rb', line 57

def punctuation
  @punctuation ||= {
    '.' => :period,
    ',' => :comma,
    ':' => :colon,
    ';' => :semicolon,

    '"' => :double_quote,
    "'" => :single_quote,
    '`' => :back_quote,

    '[' => :left_bracket,
    ']' => :right_bracket,
    '(' => :left_paren,
    ')' => :right_paren,

    '^' => :caret,
    '_' => :underscore,
    '-' => :dash,
    '~' => :tilde,

    '!' => :bang,
    '?' => :query,

    '|'       => :solid_pipe,
    "\u00A6"  => :broken_pipe,

    '/'  => :forward_slash,
    "\\" => :back_slash
  }
end

.specialObject



89
90
91
92
# File 'lib/remedy/characters.rb', line 89

def special
  {
  }
end

.whitespaceObject



33
34
35
36
37
38
39
40
# File 'lib/remedy/characters.rb', line 33

def whitespace
  @whitespace ||= {
    ?\s => :space,
    ?\t => :tab,
    ?\r => :carriage_return,
    ?\n => :line_feed
  }
end