oorb 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/oorb.rb +41 -44
- data/lib/oorb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5d8b52cb222bebd999ebf895296e15562ebc867c
|
|
4
|
+
data.tar.gz: 645d055d078fe7f092d1b1a946fee00dd1a8b126
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a0234421e5e323ec0ff88802f6c57a330e712da7551293fbea0015d7ae9f0676eac0965528ee415e1625f7ed12120d466c29dbed8ccc4b19d2215d91f98fe63
|
|
7
|
+
data.tar.gz: 291386c5a0f9ba5b74087edc83f3837f2733ad49e3dd86cb201ddd037d1f7516f24bba3882e210b7fb6d47123da2ce54d272d079bc0d129291329db72d71baa8
|
data/lib/oorb.rb
CHANGED
|
@@ -1,74 +1,71 @@
|
|
|
1
1
|
require "oorb/version"
|
|
2
|
-
LETTERS = {'s' => %w(f l j i 3 8 5),
|
|
3
|
-
'h' => %w(b),
|
|
4
|
-
'b' => %w(h),
|
|
5
|
-
'y' => %w(v j 7),
|
|
6
|
-
'c' => %w(e f d o 6),
|
|
7
|
-
'i' => %w(l 1),
|
|
8
|
-
'e' => %w(6 c d f 4 3),
|
|
9
|
-
'o' => %w(c 6 0 3 d),
|
|
10
|
-
't' => %w(i l 4),
|
|
11
|
-
'a' => %w(9),
|
|
12
|
-
'l' => %w(1 i t),
|
|
13
|
-
'v' => %w(y),
|
|
14
|
-
'f' => %w(c s),
|
|
15
|
-
'd' => %w(3 0 o),
|
|
16
|
-
'z' => %w(2),
|
|
17
|
-
'g' => %w(9 8),
|
|
18
|
-
'j' => %w(y),
|
|
19
|
-
}
|
|
20
2
|
|
|
21
3
|
##
|
|
22
4
|
# OCR Optimized Regex Builder
|
|
23
5
|
class OORB
|
|
24
|
-
def initialize
|
|
25
|
-
@letters = LETTERS
|
|
26
|
-
end
|
|
27
6
|
|
|
28
|
-
|
|
7
|
+
##
|
|
8
|
+
# Letters that regularly are mistaken in OCR and their common replacements
|
|
9
|
+
LETTERS = {'s' => %w(f l j i 3 8 5),
|
|
10
|
+
'h' => %w(b),
|
|
11
|
+
'b' => %w(h),
|
|
12
|
+
'y' => %w(v j 7),
|
|
13
|
+
'c' => %w(e f d o 6),
|
|
14
|
+
'i' => %w(l 1),
|
|
15
|
+
'e' => %w(6 c d f 4 3),
|
|
16
|
+
'o' => %w(c 6 0 3 d),
|
|
17
|
+
't' => %w(i l 4),
|
|
18
|
+
'a' => %w(9),
|
|
19
|
+
'l' => %w(1 i t),
|
|
20
|
+
'v' => %w(y),
|
|
21
|
+
'f' => %w(c s),
|
|
22
|
+
'd' => %w(3 0 o),
|
|
23
|
+
'z' => %w(2),
|
|
24
|
+
'g' => %w(9 8),
|
|
25
|
+
'j' => %w(y),
|
|
26
|
+
}
|
|
29
27
|
|
|
30
28
|
##
|
|
31
29
|
# Runs the application from the command line
|
|
32
30
|
def run
|
|
33
31
|
puts "Waiting for a statement."
|
|
34
32
|
user_input = gets.chomp
|
|
35
|
-
|
|
33
|
+
combined = combine_whitespace(user_input)
|
|
34
|
+
puts build_regex(combined)
|
|
36
35
|
run
|
|
37
36
|
end
|
|
38
37
|
|
|
39
38
|
##
|
|
40
39
|
# Builds an OCR optimized regular expression from a string
|
|
41
40
|
def build_regex(input)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
end
|
|
45
|
-
statement = input.downcase.chars.map do |l|
|
|
46
|
-
LETTERS.has_key?(l) ? build_collection(l) : l
|
|
41
|
+
input.downcase.chars.map do |char|
|
|
42
|
+
LETTERS.has_key?(char) ? build_collection(char) : escape(char)
|
|
47
43
|
end.join
|
|
48
|
-
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
##
|
|
47
|
+
# Combines whitespace characters to make " " into " "
|
|
48
|
+
def combine_whitespace(string)
|
|
49
|
+
string.gsub(/\s+/, "\s")
|
|
49
50
|
end
|
|
50
51
|
|
|
51
52
|
##
|
|
52
53
|
# Builds a group match from an input letter
|
|
53
54
|
# Raises an argument error if the letter isn't from the LETTERS hash
|
|
54
|
-
def build_collection(
|
|
55
|
-
unless LETTERS[
|
|
56
|
-
raise ArgumentError, "Valid arguments are #{LETTERS.keys.join(", ")}."
|
|
55
|
+
def build_collection(character)
|
|
56
|
+
unless LETTERS[character]
|
|
57
|
+
raise ArgumentError, "Valid arguments are a single character from #{LETTERS.keys.join(", ")}."
|
|
57
58
|
end
|
|
58
|
-
LETTERS[
|
|
59
|
-
"[#{
|
|
59
|
+
LETTERS[character].each { |x| character << x }
|
|
60
|
+
"[#{character}]"
|
|
60
61
|
end
|
|
61
62
|
|
|
62
63
|
##
|
|
63
|
-
# Escapes
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
.gsub(/\(/, "\\(") # escape open parens
|
|
70
|
-
.gsub(/\)/, "\\)") # escape close parens
|
|
71
|
-
.gsub(/\{/, "\\{") # escape open curly braces
|
|
72
|
-
.gsub(/\}/, "\\}") # escape open curly braces
|
|
64
|
+
# Escapes a single-character string and makes \s optional \\s?
|
|
65
|
+
def escape(character)
|
|
66
|
+
if character.length > 1
|
|
67
|
+
raise ArgumentError, "Argument must be a single character string"
|
|
68
|
+
end
|
|
69
|
+
character == "\s" ? "\\s?" : Regexp.escape(character)
|
|
73
70
|
end
|
|
74
71
|
end
|
data/lib/oorb/version.rb
CHANGED