syllabize 0.3.0 → 0.3.1

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: 23afd6f2352f69d7c3a26bb12a82400001320734
4
- data.tar.gz: e7bd73dee7108f6ce73e07f8f1f932e43a4a78d9
3
+ metadata.gz: 1b244e59fc134e14178deb39734180a351af0b7b
4
+ data.tar.gz: 7653f1f76b9953150897b2c6f697d54646882db5
5
5
  !binary "U0hBNTEy":
6
- metadata.gz: 6214837189f911d7fddef222d33378de3d2deeb1e962168601ec799f2371f6c37a6d871de16bc54b132cd171cf89382555c067fae738b94130ab915b940dc720
7
- data.tar.gz: aab4945ee4173764d6d04fed781f8ae78c98188e82004e83793f3d43c60ade1eeb46121f3f1e354f0069465aca69aa550b09daaefe4b22d053dbb8b95760d0dd
6
+ metadata.gz: eec995cdb480749467a962f03ef4a12b838ddc2e310b6772368b8d628477755c418e4db1249a3eff5d31d81745bf626d7432fe27d1eb815c5792b33c992ecdd3
7
+ data.tar.gz: e61dd7a06a97402657b82ff1d91e107ffb1b11d77cb4f4f9c7ae97601c5b799f5291865d9f0feb7f18e9abc511bf566facace12b6b70f636a4f6449508600382
data/lib/syllabize.rb CHANGED
@@ -4,10 +4,12 @@ require 'yaml'
4
4
  module Syllabize
5
5
 
6
6
  class Counter
7
- attr_accessor :word
7
+ attr_accessor :word, :exceptions_file
8
8
 
9
9
  def initialize(word)
10
10
  @word = word
11
+ handle_non_string_input
12
+ load_exceptions
11
13
  end
12
14
 
13
15
  CONSONANTS = /[bcdfghjklmnpqrstvwxz]/i
@@ -27,8 +29,18 @@ module Syllabize
27
29
 
28
30
  private
29
31
 
32
+ def handle_non_string_input
33
+ if !(word.is_a?(String))
34
+ raise ArgumentError.new "#{word} must be a string"
35
+ end
36
+ end
37
+
38
+ def load_exceptions
39
+ @exceptions_file = YAML::load_file(File.join(__dir__, 'exceptions.yml'))
40
+ end
41
+
30
42
  def exceptions
31
- exceptions = YAML::load_file(File.join(__dir__, 'exceptions.yml'))['exceptions']
43
+ @exceptions_file['exceptions']
32
44
  end
33
45
 
34
46
  def handle_exceptions
@@ -1,3 +1,3 @@
1
1
  module Syllabize
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -96,22 +96,29 @@ describe Syllabize::Counter do
96
96
  end
97
97
 
98
98
  describe '#count_syllables' do
99
- it 'counts the syllables in a word' do
100
- { 'blizzard' => 2,
101
- 'why' => 1,
102
- 'plain' => 1,
103
- 'sticky' => 2,
104
- 'syzygy' => 3,
105
- 'yeses' => 2,
106
- 'communism' => 4,
107
- 'please' => 1,
108
- 'candle' => 2,
109
- 'handling' => 3,
110
- 'realize' => 3,
111
- 'really' => 2,
112
- 'cooperate' => 4,
113
- }.each do |word, syllable_count|
114
- expect(Syllabize::Counter.new(word).count_syllables).to eq(syllable_count)
99
+ context 'given a string' do
100
+ it 'counts the syllables in a word' do
101
+ { 'blizzard' => 2,
102
+ 'why' => 1,
103
+ 'plain' => 1,
104
+ 'sticky' => 2,
105
+ 'syzygy' => 3,
106
+ 'yeses' => 2,
107
+ 'communism' => 4,
108
+ 'please' => 1,
109
+ 'candle' => 2,
110
+ 'handling' => 3,
111
+ 'realize' => 3,
112
+ 'really' => 2,
113
+ 'cooperate' => 4,
114
+ }.each do |word, syllable_count|
115
+ expect(Syllabize::Counter.new(word).count_syllables).to eq(syllable_count), "#{word} was not the correct number of syllables"
116
+ end
117
+ end
118
+ end
119
+ context 'other data' do
120
+ it 'raises an error' do
121
+ expect { Syllabize::Counter.new(7) }.to raise_error
115
122
  end
116
123
  end
117
124
  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.3.0
4
+ version: 0.3.1
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-25 00:00:00.000000000 Z
11
+ date: 2013-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler