syllabize 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: a422a9a9ed9a5bf6424f003baa3945a5f53124e5
4
- data.tar.gz: 8aa772696411696a4efb223a75cbd2871872e0d4
3
+ metadata.gz: 23afd6f2352f69d7c3a26bb12a82400001320734
4
+ data.tar.gz: e7bd73dee7108f6ce73e07f8f1f932e43a4a78d9
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: 3f13ff4bb4b1b6868327fcf0654ada458fb67b673f4d42fa4a73a94a708163a1f6b4bd490b3daa8a8544b24026e564cd4361b6ad7e52db9c7a9fa859c3810c5a
7
- data.tar.gz: db2a078e4706bf32c4f4c23890d958eb1db3384cf1a76dc4c81ebffc38c731f3258eb31f699f05cc59cba2d536686d08c3d751cdad3b7250e11eaf21239de8f7
6
+ metadata.gz: 6214837189f911d7fddef222d33378de3d2deeb1e962168601ec799f2371f6c37a6d871de16bc54b132cd171cf89382555c067fae738b94130ab915b940dc720
7
+ data.tar.gz: aab4945ee4173764d6d04fed781f8ae78c98188e82004e83793f3d43c60ade1eeb46121f3f1e354f0069465aca69aa550b09daaefe4b22d053dbb8b95760d0dd
@@ -0,0 +1,4 @@
1
+ ---
2
+ exceptions:
3
+ really: 2
4
+ cooperate: 4
data/lib/syllabize.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "syllabize/version"
2
+ require 'yaml'
2
3
 
3
4
  module Syllabize
4
5
 
@@ -14,19 +15,38 @@ module Syllabize
14
15
  LE_VOWEL_SOUND = /((le)\z)|((le(d|r|s))|(ling)\z)/i
15
16
  DIPHTHONGS = /ou|ie|oo|oi|ea|ee|ai|ae/i
16
17
  Y_AS_VOWEL = /[^yY][yY]/
18
+ RE_VOWEL = /(^re[aeiou])/i
17
19
 
18
20
  def count_syllables
19
- syllables = count_vowels
20
- syllables -= 1 if ends_in_silent_e?
21
- syllables -= count_diphthongs if contains_diphthongs?
22
- syllables += count_ys_in_vowel_role if contains_non_initial_y?
23
- syllables += 1 if contains_le_vowel_sound?
24
- syllables += 1 if ends_in_sm?
25
- syllables <= 1 ? 1 : syllables
21
+ return handle_exceptions if exceptions.keys.include?(word)
22
+ @syllables = count_vowels
23
+ handle_additions
24
+ handle_subtractions
25
+ @syllables <= 1 ? 1 : @syllables
26
26
  end
27
27
 
28
28
  private
29
29
 
30
+ def exceptions
31
+ exceptions = YAML::load_file(File.join(__dir__, 'exceptions.yml'))['exceptions']
32
+ end
33
+
34
+ def handle_exceptions
35
+ exceptions[word.to_s]
36
+ end
37
+
38
+ def handle_additions
39
+ @syllables += count_ys_in_vowel_role if contains_non_initial_y?
40
+ if contains_le_vowel_sound? || begins_with_re_vowel? || ends_in_sm?
41
+ @syllables += 1
42
+ end
43
+ end
44
+
45
+ def handle_subtractions
46
+ @syllables -= 1 if ends_in_silent_e?
47
+ @syllables -= count_diphthongs if contains_diphthongs?
48
+ end
49
+
30
50
  def count_vowels
31
51
  word.scan(VOWELS).count
32
52
  end
@@ -47,6 +67,10 @@ module Syllabize
47
67
  word.scan(Y_AS_VOWEL).size
48
68
  end
49
69
 
70
+ def begins_with_re_vowel?
71
+ word.scan(RE_VOWEL).any?
72
+ end
73
+
50
74
  def contains_diphthongs?
51
75
  word.downcase.scan(DIPHTHONGS).any?
52
76
  end
@@ -1,3 +1,3 @@
1
1
  module Syllabize
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -3,7 +3,8 @@ require_relative '../spec_helper'
3
3
  class Syllabize::Counter
4
4
  public :count_vowels, :ends_in_silent_e?, :count_diphthongs,
5
5
  :contains_diphthongs?, :ends_in_sm?, :contains_non_initial_y?,
6
- :count_ys_in_vowel_role, :contains_le_vowel_sound?
6
+ :count_ys_in_vowel_role, :contains_le_vowel_sound?,
7
+ :begins_with_re_vowel?
7
8
  end
8
9
 
9
10
  describe Syllabize::Counter do
@@ -74,6 +75,13 @@ describe Syllabize::Counter do
74
75
  end
75
76
  end
76
77
 
78
+ describe '#begins_with_re_vowel?' do
79
+ it 'returns true if the word begins with re- and a vowel' do
80
+ expect(Syllabize::Counter.new('rearrange').begins_with_re_vowel?).to be_true
81
+ expect(Syllabize::Counter.new('dreary').begins_with_re_vowel?).to be_false
82
+ end
83
+ end
84
+
77
85
  describe '#count_diphthongs' do
78
86
  it 'counts the diphthongs in a word' do
79
87
  expect(Syllabize::Counter.new('air').count_diphthongs).to eq(1)
@@ -99,6 +107,9 @@ describe Syllabize::Counter do
99
107
  'please' => 1,
100
108
  'candle' => 2,
101
109
  'handling' => 3,
110
+ 'realize' => 3,
111
+ 'really' => 2,
112
+ 'cooperate' => 4,
102
113
  }.each do |word, syllable_count|
103
114
  expect(Syllabize::Counter.new(word).count_syllables).to eq(syllable_count)
104
115
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syllabize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thenickcox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-24 00:00:00.000000000 Z
11
+ date: 2013-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -64,6 +64,7 @@ files:
64
64
  - LICENSE.txt
65
65
  - README.md
66
66
  - Rakefile
67
+ - lib/exceptions.yml
67
68
  - lib/syllabize.rb
68
69
  - lib/syllabize/version.rb
69
70
  - spec/lib/syllabize_spec.rb