syllabize 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/exceptions.yml +2 -0
- data/lib/syllabize.rb +6 -3
- data/lib/syllabize/version.rb +1 -1
- data/spec/lib/syllabize_spec.rb +8 -4
- metadata +1 -1
data/lib/exceptions.yml
CHANGED
data/lib/syllabize.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'syllabize/version'
|
2
1
|
require 'yaml'
|
3
2
|
|
4
3
|
module Syllabize
|
@@ -7,7 +6,7 @@ module Syllabize
|
|
7
6
|
attr_accessor :word, :exceptions_file
|
8
7
|
|
9
8
|
def initialize(word)
|
10
|
-
@word = word
|
9
|
+
@word = strip_apostrophes(word)
|
11
10
|
handle_non_string_input
|
12
11
|
load_exceptions
|
13
12
|
end
|
@@ -34,6 +33,10 @@ module Syllabize
|
|
34
33
|
File.dirname(__FILE__)
|
35
34
|
end unless respond_to?(:__dir__, true)
|
36
35
|
|
36
|
+
def strip_apostrophes(string)
|
37
|
+
string.gsub("'",'')
|
38
|
+
end
|
39
|
+
|
37
40
|
def handle_non_string_input
|
38
41
|
if !(word.is_a?(String))
|
39
42
|
raise ArgumentError.new "#{word} must be a string"
|
@@ -69,7 +72,7 @@ module Syllabize
|
|
69
72
|
end
|
70
73
|
|
71
74
|
def ends_in_silent_e?
|
72
|
-
word.downcase.each_char.to_a
|
75
|
+
word.downcase.each_char.to_a.last == 'e'
|
73
76
|
end
|
74
77
|
|
75
78
|
def contains_le_vowel_sound?
|
data/lib/syllabize/version.rb
CHANGED
data/spec/lib/syllabize_spec.rb
CHANGED
@@ -98,7 +98,8 @@ describe Syllabize::Counter do
|
|
98
98
|
describe '#count_syllables' do
|
99
99
|
context 'given a string' do
|
100
100
|
it 'counts the syllables in a word' do
|
101
|
-
{
|
101
|
+
{
|
102
|
+
'blizzard' => 2,
|
102
103
|
'why' => 1,
|
103
104
|
'plain' => 1,
|
104
105
|
'sticky' => 2,
|
@@ -111,9 +112,12 @@ describe Syllabize::Counter do
|
|
111
112
|
'realize' => 3,
|
112
113
|
'really' => 2,
|
113
114
|
'cooperate' => 4,
|
114
|
-
'ways' => 1
|
115
|
-
|
116
|
-
|
115
|
+
'ways' => 1,
|
116
|
+
"Wayne's" => 1,
|
117
|
+
'basement' => 2
|
118
|
+
}.each do |word, actual|
|
119
|
+
count = Syllabize::Counter.new(word).count_syllables
|
120
|
+
expect(count).to eq(actual), "#{word} was not the correct number of syllables; expected #{actual}, was #{count}"
|
117
121
|
end
|
118
122
|
end
|
119
123
|
end
|