braille_ueb 0.0.2 → 0.0.3
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.
- data/lib/braille_ueb.rb +1 -0
- data/lib/braille_ueb/char.rb +5 -1
- data/lib/braille_ueb/constants.rb +31 -10
- data/lib/braille_ueb/token.rb +23 -0
- data/lib/braille_ueb/version.rb +1 -1
- data/lib/braille_ueb/word.rb +24 -62
- data/spec/braille_ueb_spec.rb +12 -0
- metadata +5 -4
data/lib/braille_ueb.rb
CHANGED
data/lib/braille_ueb/char.rb
CHANGED
@@ -2,7 +2,7 @@ module BrailleUEB
|
|
2
2
|
class Char < String
|
3
3
|
|
4
4
|
def upper?
|
5
|
-
c == c.upcase
|
5
|
+
c == c.upcase && !number?
|
6
6
|
end
|
7
7
|
|
8
8
|
def number?
|
@@ -17,6 +17,10 @@ module BrailleUEB
|
|
17
17
|
ALPHA.has_key?(c.downcase)
|
18
18
|
end
|
19
19
|
|
20
|
+
def alphanumeric?
|
21
|
+
letter? || number?
|
22
|
+
end
|
23
|
+
|
20
24
|
private
|
21
25
|
|
22
26
|
def c
|
@@ -53,17 +53,38 @@ module BrailleUEB
|
|
53
53
|
',' => '⠂'
|
54
54
|
}
|
55
55
|
|
56
|
+
GROUPS = {
|
57
|
+
'and' => '⠯',
|
58
|
+
'for' => '⠿',
|
59
|
+
'of' => '⠷',
|
60
|
+
'the' => '⠮',
|
61
|
+
'with' => '⠾',
|
62
|
+
}
|
63
|
+
|
56
64
|
CONTRACTIONS = {
|
57
|
-
'
|
58
|
-
'
|
59
|
-
'
|
60
|
-
'
|
61
|
-
'
|
62
|
-
'
|
63
|
-
'
|
64
|
-
'
|
65
|
-
'
|
66
|
-
'
|
65
|
+
'but' => '⠃',
|
66
|
+
'can' => '⠉',
|
67
|
+
'do' => '⠙',
|
68
|
+
'every' => '⠑',
|
69
|
+
'from' => '⠋',
|
70
|
+
'go' => '⠛',
|
71
|
+
'have' => '⠓',
|
72
|
+
'just' => '⠚',
|
73
|
+
'knowledge' => '⠅',
|
74
|
+
'like' => '⠇',
|
75
|
+
'more' => '⠍',
|
76
|
+
'not' => '⠝',
|
77
|
+
'people' => '⠏',
|
78
|
+
'quite' => '⠟',
|
79
|
+
'rather' => '⠗',
|
80
|
+
'so' => '⠎',
|
81
|
+
'that' => '⠞',
|
82
|
+
'us' => '⠥',
|
83
|
+
'very' => '⠧',
|
84
|
+
'will' => '⠺',
|
85
|
+
'it' => '⠭',
|
86
|
+
'you' => '⠽',
|
87
|
+
'as' => '⠵'
|
67
88
|
}
|
68
89
|
|
69
90
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module BrailleUEB
|
2
|
+
class Token
|
3
|
+
def initialize(token)
|
4
|
+
@word, @punc = split(token)
|
5
|
+
end
|
6
|
+
|
7
|
+
def translate
|
8
|
+
braille = @word.translate
|
9
|
+
braille << PUNCTUATION[@punc] if @punc
|
10
|
+
braille
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def split(token)
|
16
|
+
punctuation = PUNCTUATION.keys.join("")
|
17
|
+
word = token.tr(punctuation, "")
|
18
|
+
punc = token.match("[#{punctuation}]")
|
19
|
+
punc = punc[0] if punc
|
20
|
+
[ Word.new(word), punc ]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/braille_ueb/version.rb
CHANGED
data/lib/braille_ueb/word.rb
CHANGED
@@ -1,85 +1,47 @@
|
|
1
1
|
module BrailleUEB
|
2
|
-
class Token
|
3
|
-
def initialize(token)
|
4
|
-
@word, @punc = split(token)
|
5
|
-
end
|
6
|
-
|
7
|
-
def translate
|
8
|
-
braille = @word.translate
|
9
|
-
braille << PUNCTUATION[@punc] if @punc
|
10
|
-
braille
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
def split(token)
|
16
|
-
punctuation = PUNCTUATION.keys.join("")
|
17
|
-
word = token.tr(punctuation, "")
|
18
|
-
punc = token.match("[#{punctuation}]")
|
19
|
-
punc = punc[0] if punc
|
20
|
-
[ Word.new(word), punc ]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
2
|
class Word
|
25
3
|
def initialize(word)
|
26
4
|
@word = word
|
27
5
|
end
|
28
6
|
|
29
7
|
def translate
|
30
|
-
if
|
31
|
-
contracted
|
32
|
-
else
|
33
|
-
letter_by_letter
|
34
|
-
end
|
35
|
-
end
|
8
|
+
return "" if @word.empty?
|
36
9
|
|
37
|
-
private
|
38
|
-
|
39
|
-
def contraction?
|
40
|
-
CONTRACTIONS.has_key?(@word.downcase)
|
41
|
-
end
|
42
|
-
|
43
|
-
def contracted
|
44
10
|
braille = ""
|
45
11
|
braille << SPECIAL[:capital] if starts_with_upper?
|
46
|
-
braille <<
|
47
|
-
braille
|
48
|
-
end
|
12
|
+
braille << SPECIAL[:number] if starts_with_number?
|
13
|
+
braille << @word.downcase
|
49
14
|
|
50
|
-
|
51
|
-
|
52
|
-
|
15
|
+
CONTRACTIONS.each { |key, val|
|
16
|
+
braille = braille.gsub(key, val)
|
17
|
+
}
|
53
18
|
|
54
|
-
|
55
|
-
|
56
|
-
|
19
|
+
GROUPS.each { |key, val|
|
20
|
+
braille = braille.gsub(key, val)
|
21
|
+
}
|
57
22
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
23
|
+
ALPHA.each { |key, val|
|
24
|
+
braille = braille.gsub(key, val)
|
25
|
+
}
|
26
|
+
|
27
|
+
NUMBER.each { |key, val|
|
28
|
+
braille = braille.gsub(key, val)
|
29
|
+
}
|
63
30
|
|
64
31
|
braille
|
65
|
-
end
|
66
32
|
|
67
|
-
|
68
|
-
result = ""
|
33
|
+
end
|
69
34
|
|
70
|
-
|
71
|
-
result << SPECIAL[:capital] if c.upper?
|
72
|
-
result << ALPHA[c.downcase]
|
73
|
-
elsif c.number?
|
74
|
-
result << SPECIAL[:number] unless previous.number?
|
75
|
-
result << NUMBER[c]
|
76
|
-
else
|
77
|
-
result << c
|
78
|
-
end
|
35
|
+
private
|
79
36
|
|
80
|
-
|
37
|
+
def starts_with_upper?
|
38
|
+
Char.new(@word[0]).upper?
|
81
39
|
end
|
82
40
|
|
41
|
+
def starts_with_number?
|
42
|
+
Char.new(@word[0]).number?
|
43
|
+
end
|
44
|
+
|
83
45
|
end
|
84
46
|
end
|
85
47
|
|
data/spec/braille_ueb_spec.rb
CHANGED
@@ -9,6 +9,10 @@ describe BrailleUEB do
|
|
9
9
|
verify 'c', '⠉'
|
10
10
|
end
|
11
11
|
|
12
|
+
it 'should convert the same letter in a row' do
|
13
|
+
verify 'zz', '⠵⠵'
|
14
|
+
end
|
15
|
+
|
12
16
|
it 'should convert capital letters' do
|
13
17
|
verify 'Z', '⠠⠵'
|
14
18
|
end
|
@@ -35,6 +39,14 @@ describe BrailleUEB do
|
|
35
39
|
verify 'like', '⠇'
|
36
40
|
end
|
37
41
|
|
42
|
+
it 'should handle special wordsigns' do
|
43
|
+
verify 'and', '⠯'
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should handle group signs' do
|
47
|
+
verify 'band', '⠃⠯'
|
48
|
+
end
|
49
|
+
|
38
50
|
it 'should perform contractions that end with punctuation' do
|
39
51
|
verify 'like.', '⠇⠲'
|
40
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: braille_ueb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A translator for Unified English Braille (UEB)
|
15
15
|
email: chris@geihsler.net
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- Rakefile
|
21
21
|
- lib/braille_ueb/char.rb
|
22
22
|
- lib/braille_ueb/constants.rb
|
23
|
+
- lib/braille_ueb/token.rb
|
23
24
|
- lib/braille_ueb/version.rb
|
24
25
|
- lib/braille_ueb/word.rb
|
25
26
|
- lib/braille_ueb.rb
|
@@ -33,17 +34,17 @@ rdoc_options: []
|
|
33
34
|
require_paths:
|
34
35
|
- lib
|
35
36
|
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
37
|
requirements:
|
38
38
|
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
41
|
none: false
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - ! '>='
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
|
+
none: false
|
47
48
|
requirements: []
|
48
49
|
rubyforge_project:
|
49
50
|
rubygems_version: 1.8.24
|