syllabize 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: 9e4095fbf7709fecd8a9bb515065decda09e63bf
4
- data.tar.gz: 0cde126c3666b2f303d22b7beec0b40f32c17a5c
3
+ metadata.gz: a422a9a9ed9a5bf6424f003baa3945a5f53124e5
4
+ data.tar.gz: 8aa772696411696a4efb223a75cbd2871872e0d4
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: 47bc7d2d2104e14aaacca4566dcdb540977ddaf4ff81afb73ca0945570329f1d902e72b40d07bc0ec029f1d4404ac7723fdf1d9ce259d8d954c24730a72e9cf6
7
- data.tar.gz: 68f7b68bab2ab24b966bbe4ff0c649faf3242d26c130e37085a266dd1f77ca287592675cb4dd2f79b73f6bd1ae3aefe114933fcbec1d5ceec339641e343e171a
6
+ metadata.gz: 3f13ff4bb4b1b6868327fcf0654ada458fb67b673f4d42fa4a73a94a708163a1f6b4bd490b3daa8a8544b24026e564cd4361b6ad7e52db9c7a9fa859c3810c5a
7
+ data.tar.gz: db2a078e4706bf32c4f4c23890d958eb1db3384cf1a76dc4c81ebffc38c731f3258eb31f699f05cc59cba2d536686d08c3d751cdad3b7250e11eaf21239de8f7
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ .*.sw?
3
4
  .bundle
4
5
  .config
5
6
  .yardoc
data/README.md CHANGED
@@ -22,7 +22,7 @@ First, require `syllabize`. Then, you can call the `count_vowels` method on a st
22
22
 
23
23
  ```ruby
24
24
  Syllabize::Counter.new('Ruby').count_syllables
25
- # => 4
25
+ # => 2
26
26
  ```
27
27
 
28
28
  ## Contributing
@@ -11,14 +11,17 @@ module Syllabize
11
11
 
12
12
  CONSONANTS = /[bcdfghjklmnpqrstvwxz]/i
13
13
  VOWELS = /[aeiou]/i
14
- CONSONANT_E = /le/i
14
+ LE_VOWEL_SOUND = /((le)\z)|((le(d|r|s))|(ling)\z)/i
15
15
  DIPHTHONGS = /ou|ie|oo|oi|ea|ee|ai|ae/i
16
+ Y_AS_VOWEL = /[^yY][yY]/
16
17
 
17
18
  def count_syllables
18
19
  syllables = count_vowels
19
20
  syllables -= 1 if ends_in_silent_e?
20
21
  syllables -= count_diphthongs if contains_diphthongs?
21
- syllables += 1 if ends_in_y?
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?
22
25
  syllables <= 1 ? 1 : syllables
23
26
  end
24
27
 
@@ -29,12 +32,19 @@ module Syllabize
29
32
  end
30
33
 
31
34
  def ends_in_silent_e?
32
- return false if word.downcase.scan(CONSONANT_E).any?
33
35
  word.downcase.each_char.to_a[-1] == 'e'
34
36
  end
35
37
 
36
- def ends_in_y?
37
- word.downcase.end_with?('y')
38
+ def contains_le_vowel_sound?
39
+ word.scan(LE_VOWEL_SOUND).any?
40
+ end
41
+
42
+ def contains_non_initial_y?
43
+ count_ys_in_vowel_role > 0
44
+ end
45
+
46
+ def count_ys_in_vowel_role
47
+ word.scan(Y_AS_VOWEL).size
38
48
  end
39
49
 
40
50
  def contains_diphthongs?
@@ -44,6 +54,10 @@ module Syllabize
44
54
  def count_diphthongs
45
55
  word.downcase.scan(DIPHTHONGS).count
46
56
  end
57
+
58
+ def ends_in_sm?
59
+ word.end_with?('sm')
60
+ end
47
61
  end
48
62
 
49
63
  end
@@ -1,3 +1,3 @@
1
1
  module Syllabize
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,108 @@
1
+ require_relative '../spec_helper'
2
+
3
+ class Syllabize::Counter
4
+ public :count_vowels, :ends_in_silent_e?, :count_diphthongs,
5
+ :contains_diphthongs?, :ends_in_sm?, :contains_non_initial_y?,
6
+ :count_ys_in_vowel_role, :contains_le_vowel_sound?
7
+ end
8
+
9
+ describe Syllabize::Counter do
10
+
11
+ describe '#count_vowels' do
12
+ let(:word) { 'America' }
13
+ it 'counts the vowels in a word' do
14
+ expect(Syllabize::Counter.new(word).count_vowels).to eql(4)
15
+ end
16
+ end
17
+
18
+ describe '#ends_in_silent_e?' do
19
+ context 'silent e' do
20
+ it 'returns true if the word ends in a silent e' do
21
+ expect(Syllabize::Counter.new('kite').ends_in_silent_e?).to be_true
22
+ end
23
+ end
24
+ context 'not silent e' do
25
+ it 'returns false if the word ends in e but is not silent' do
26
+ expect(Syllabize::Counter.new('now').ends_in_silent_e?).to be_false
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#contains_le_vowel_sound?' do
32
+ context 'does contain' do
33
+ it 'returns true if the word contains -le as a vowel sound' do
34
+ expect(Syllabize::Counter.new('castle').contains_le_vowel_sound?).to be_true
35
+ end
36
+ end
37
+ context 'does not contain' do
38
+ it 'returns false if the word does not contain le vowel' do
39
+ expect(Syllabize::Counter.new('no').contains_le_vowel_sound?).to be_false
40
+ end
41
+ end
42
+ end
43
+
44
+ describe '#contains_non_initial_y?' do
45
+ context 'has a y in middle or end of word' do
46
+ it 'returns true if the word ends in y' do
47
+ expect(Syllabize::Counter.new('sticky').contains_non_initial_y?).to be_true
48
+ end
49
+ end
50
+ context 'begins with y' do
51
+ it 'returns false if the word does not end in y' do
52
+ expect(Syllabize::Counter.new('yes').contains_non_initial_y?).to be_false
53
+ end
54
+ end
55
+ context 'does not contain y' do
56
+ it 'returns false if the word does not contain y' do
57
+ expect(Syllabize::Counter.new('please').contains_non_initial_y?).to be_false
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '#count_ys_in_vowel_role' do
63
+ context '2 ys in vowel role' do
64
+ it 'returns 2 for ys_in_vowel_role' do
65
+ expect(Syllabize::Counter.new('slyly').count_ys_in_vowel_role).to eq(2)
66
+ end
67
+ end
68
+ end
69
+
70
+ describe '#contains_diphthongs' do
71
+ let(:word) { 'ear' }
72
+ it 'returns true if the word contains diphthongs' do
73
+ expect(Syllabize::Counter.new(word).contains_diphthongs?).to be_true
74
+ end
75
+ end
76
+
77
+ describe '#count_diphthongs' do
78
+ it 'counts the diphthongs in a word' do
79
+ expect(Syllabize::Counter.new('air').count_diphthongs).to eq(1)
80
+ expect(Syllabize::Counter.new('aerie').count_diphthongs).to eq(2)
81
+ end
82
+ end
83
+
84
+ describe '#ends_in_sm?' do
85
+ it 'returns true if the word ends in -sm' do
86
+ expect(Syllabize::Counter.new('communism').ends_in_sm?).to be_true
87
+ end
88
+ end
89
+
90
+ describe '#count_syllables' do
91
+ it 'counts the syllables in a word' do
92
+ { 'blizzard' => 2,
93
+ 'why' => 1,
94
+ 'plain' => 1,
95
+ 'sticky' => 2,
96
+ 'syzygy' => 3,
97
+ 'yeses' => 2,
98
+ 'communism' => 4,
99
+ 'please' => 1,
100
+ 'candle' => 2,
101
+ 'handling' => 3,
102
+ }.each do |word, syllable_count|
103
+ expect(Syllabize::Counter.new(word).count_syllables).to eq(syllable_count)
104
+ end
105
+ end
106
+ end
107
+
108
+ end
@@ -0,0 +1,14 @@
1
+ require 'syllabize'
2
+ require 'syllabize/version'
3
+ require 'rspec'
4
+
5
+ RSpec.configure do |config|
6
+ # Use color in STDOUT
7
+ config.color_enabled = true
8
+
9
+ # Use color not only in STDOUT but also in pagers and files
10
+ config.tty = true
11
+
12
+ # Use the specified formatter
13
+ config.formatter = :documentation # :progress, :html, :textmate
14
+ 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.1.0
4
+ version: 0.2.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-21 00:00:00.000000000 Z
11
+ date: 2013-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,8 @@ files:
66
66
  - Rakefile
67
67
  - lib/syllabize.rb
68
68
  - lib/syllabize/version.rb
69
+ - spec/lib/syllabize_spec.rb
70
+ - spec/spec_helper.rb
69
71
  - syllabize.gemspec
70
72
  homepage: http://github.com/thenickcox/syllabize
71
73
  licenses:
@@ -91,4 +93,6 @@ rubygems_version: 2.0.0
91
93
  signing_key:
92
94
  specification_version: 4
93
95
  summary: Syllabize counts the number of syllables in a gem
94
- test_files: []
96
+ test_files:
97
+ - spec/lib/syllabize_spec.rb
98
+ - spec/spec_helper.rb