rhopalic 0.0.1 → 0.0.2
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/rhopalic/analysis.rb +11 -4
- data/lib/rhopalic/version.rb +1 -1
- data/test/rhopalic_test.rb +7 -0
- metadata +2 -2
data/lib/rhopalic/analysis.rb
CHANGED
@@ -19,16 +19,23 @@ module Rhopalic
|
|
19
19
|
is_letter_rhopalic = true
|
20
20
|
is_syllable_rhopalic = true
|
21
21
|
|
22
|
-
|
22
|
+
# Explanation of this regex:
|
23
|
+
# - [:alpha:] matches alphabetic characters throughout the whole unicode set
|
24
|
+
# - we use word boundaries (\b) to delineate words
|
25
|
+
# - however, word boundaries don't match before and after underscore, so we
|
26
|
+
# explicitly treat that as a word boundary
|
27
|
+
# - using positive lookahead (?=...) because otherwise we'd miss words where
|
28
|
+
# they are only separated by an underscore
|
29
|
+
phrase.scan(/(\b|_)([[:alpha:]\d]+)(?=\b|_)/) do
|
23
30
|
match = Regexp.last_match
|
24
|
-
word = match[
|
31
|
+
word = match[2]
|
25
32
|
index = match.begin(0)
|
26
33
|
is_number = false
|
27
34
|
|
28
35
|
# Bail out on words that contain numbers, unless we can pronounce the number
|
29
36
|
# as a whole word.
|
30
|
-
word.match(/\d+/) do |
|
31
|
-
return nil if
|
37
|
+
word.match(/\d+/) do |num_match|
|
38
|
+
return nil if num_match[0].size != word.size
|
32
39
|
is_number = true
|
33
40
|
end
|
34
41
|
|
data/lib/rhopalic/version.rb
CHANGED
data/test/rhopalic_test.rb
CHANGED
@@ -15,6 +15,7 @@ class Rhopalic::RhopalicTest < ActiveSupport::TestCase
|
|
15
15
|
"IT'S FANCY",
|
16
16
|
"it's'bleak matter",
|
17
17
|
"rose's stencil",
|
18
|
+
"a_be_the",
|
18
19
|
] do |phrase|
|
19
20
|
assert Rhopalic.letter_rhopalic?(phrase)
|
20
21
|
assert Rhopalic.rhopalic?(phrase)
|
@@ -38,6 +39,7 @@ class Rhopalic::RhopalicTest < ActiveSupport::TestCase
|
|
38
39
|
"be do",
|
39
40
|
"a be ce",
|
40
41
|
"a it's fancy",
|
42
|
+
"@DannyBoo_ go get some sleep",
|
41
43
|
] do |phrase|
|
42
44
|
assert !Rhopalic.rhopalic?(phrase)
|
43
45
|
end
|
@@ -70,4 +72,9 @@ class Rhopalic::RhopalicTest < ActiveSupport::TestCase
|
|
70
72
|
assert_equal [0, 4], phrase.indices
|
71
73
|
assert_equal [1, 1], phrase.syllable_counts
|
72
74
|
end
|
75
|
+
|
76
|
+
def test_analyze_phrase_with_underscores
|
77
|
+
phrase = Rhopalic.analyze_phrase("two_four_eight")
|
78
|
+
assert_equal ["two", "four", "eight"], phrase.words
|
79
|
+
end
|
73
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhopalic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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: 2013-04-
|
12
|
+
date: 2013-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: lingua
|