word_count_analyzer 0.0.14 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ module WordCountAnalyzer
9
9
  end
10
10
 
11
11
  def hyphenated_word?
12
- (token.include?('-') || token.include?('﹘')) && !WordCountAnalyzer::Hyperlink.new(string: token).hyperlink?
12
+ (token.include?('-') || token.include?('﹘')) && !WordCountAnalyzer::Hyperlink.new.hyperlink?(token)
13
13
  end
14
14
 
15
15
  def count_as_multiple
@@ -5,7 +5,7 @@ module WordCountAnalyzer
5
5
 
6
6
  attr_reader :string
7
7
  def initialize(string:)
8
- @string = WordCountAnalyzer::NumberedList.new(string: WordCountAnalyzer::Date.new(string: string).replace).replace
8
+ @string = WordCountAnalyzer::NumberedList.new(string: WordCountAnalyzer::Date.new.replace(string)).replace
9
9
  end
10
10
 
11
11
  def includes_number?
@@ -12,32 +12,33 @@ module WordCountAnalyzer
12
12
  @date = args[:date] || nil
13
13
  @xhtml = args[:xhtml] || nil
14
14
  @hyperlink = args[:hyperlink] || nil
15
+ hyper = WordCountAnalyzer::Hyperlink.new
15
16
  if date.eql?('no_special_treatment')
16
17
  if xhtml.eql?('keep')
17
18
  if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period')
18
19
  @processed_string = string
19
20
  else
20
- @processed_string = WordCountAnalyzer::Hyperlink.new(string: string).replace
21
+ @processed_string = hyper.replace(string)
21
22
  end
22
23
  else
23
24
  if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period')
24
25
  @processed_string = WordCountAnalyzer::Xhtml.new(string: string).replace
25
26
  else
26
- @processed_string = WordCountAnalyzer::Xhtml.new(string: WordCountAnalyzer::Hyperlink.new(string: string).replace).replace
27
+ @processed_string = WordCountAnalyzer::Xhtml.new(string: hyper.replace(string)).replace
27
28
  end
28
29
  end
29
30
  else
30
31
  if xhtml.eql?('keep')
31
32
  if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period')
32
- @processed_string = WordCountAnalyzer::Date.new(string: string).replace
33
+ @processed_string = WordCountAnalyzer::Date.new.replace(string)
33
34
  else
34
- @processed_string = WordCountAnalyzer::Date.new(string: WordCountAnalyzer::Hyperlink.new(string: string).replace).replace
35
+ @processed_string = WordCountAnalyzer::Date.new.replace(hyper.replace(string))
35
36
  end
36
37
  else
37
38
  if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period')
38
- @processed_string = WordCountAnalyzer::Date.new(string: WordCountAnalyzer::Xhtml.new(string: string).replace).replace
39
+ @processed_string = WordCountAnalyzer::Date.new.replace(WordCountAnalyzer::Xhtml.new(string: string).replace)
39
40
  else
40
- @processed_string = WordCountAnalyzer::Date.new(string: WordCountAnalyzer::Xhtml.new(string: WordCountAnalyzer::Hyperlink.new(string: string).replace).replace).replace
41
+ @processed_string = WordCountAnalyzer::Date.new.replace(WordCountAnalyzer::Xhtml.new(string: hyper.replace(string)).replace)
41
42
  end
42
43
  end
43
44
  end
@@ -65,7 +66,7 @@ module WordCountAnalyzer
65
66
 
66
67
  def replace_forward_slashes_except_dates
67
68
  return processed_string if processed_string !~ FORWARD_SLASH_REGEX
68
- except_date_string = WordCountAnalyzer::Date.new(string: processed_string).replace_number_only_date
69
+ except_date_string = WordCountAnalyzer::Date.new.replace_number_only_date(processed_string)
69
70
  except_date_string.gsub!(FORWARD_SLASH_REGEX).each do |match|
70
71
  match.split(/\/+/).join(' ')
71
72
  end
@@ -1,3 +1,3 @@
1
1
  module WordCountAnalyzer
2
- VERSION = "0.0.14"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -4,503 +4,469 @@ RSpec.describe WordCountAnalyzer::Counter do
4
4
  context 'ellipsis' do
5
5
  it 'handles an invalid ellipsis argument value' do
6
6
  text = 'hello world.'
7
- ws = WordCountAnalyzer::Counter.new(text: text, ellipsis: 'hello')
8
- expect { ws.count }.to raise_error('The value you specified for ellipsis is not a valid option. Please use either `ignore` or `no_special_treatment`. The default option is `ignore`')
7
+ ws = WordCountAnalyzer::Counter.new(ellipsis: 'hello')
8
+ expect { ws.count(text) }.to raise_error('The value you specified for ellipsis is not a valid option. Please use either `ignore` or `no_special_treatment`. The default option is `ignore`')
9
9
  end
10
10
 
11
11
  it 'ignores ellipses in the word count' do
12
12
  text = 'hello world ... what day is it.'
13
13
  ws = WordCountAnalyzer::Counter.new(
14
- text: text,
15
14
  ellipsis: 'ignore'
16
15
  )
17
- expect(ws.count).to eq(6)
16
+ expect(ws.count(text)).to eq(6)
18
17
  end
19
18
 
20
19
  it 'does not ignore ellipses in the word count' do
21
20
  text = 'hello world ... what day is it.'
22
21
  ws = WordCountAnalyzer::Counter.new(
23
- text: text,
24
22
  ellipsis: 'no_special_treatment'
25
23
  )
26
- expect(ws.count).to eq(7)
24
+ expect(ws.count(text)).to eq(7)
27
25
  end
28
26
 
29
27
  it 'does not ignore ellipses in the word count' do
30
28
  text = 'hello world... what day is it.'
31
29
  ws = WordCountAnalyzer::Counter.new(
32
- text: text,
33
30
  ellipsis: 'no_special_treatment'
34
31
  )
35
- expect(ws.count).to eq(6)
32
+ expect(ws.count(text)).to eq(6)
36
33
  end
37
34
 
38
35
  it 'sets ignore as the default option' do
39
36
  text = 'hello world ... what day is it.'
40
- ws = WordCountAnalyzer::Counter.new(text: text)
41
- expect(ws.count).to eq(6)
37
+ ws = WordCountAnalyzer::Counter.new
38
+ expect(ws.count(text)).to eq(6)
42
39
  end
43
40
  end
44
41
 
45
42
  context 'hyperlink' do
46
43
  it 'handles an invalid hyperlink argument value' do
47
44
  text = 'hello world.'
48
- ws = WordCountAnalyzer::Counter.new(text: text, hyperlink: 'hello')
49
- expect { ws.count }.to raise_error('The value you specified for hyperlink is not a valid option. Please use either `count_as_one`, `split_at_period`, or `no_special_treatment`. The default option is `count_as_one`')
45
+ ws = WordCountAnalyzer::Counter.new(hyperlink: 'hello')
46
+ expect { ws.count(text) }.to raise_error('The value you specified for hyperlink is not a valid option. Please use either `count_as_one`, `split_at_period`, or `no_special_treatment`. The default option is `count_as_one`')
50
47
  end
51
48
 
52
49
  it 'counts a hyperlink as one word in the word count' do
53
50
  text = 'The site address is http://www.example.com she said.'
54
51
  ws = WordCountAnalyzer::Counter.new(
55
- text: text,
56
52
  hyperlink: 'count_as_one'
57
53
  )
58
- expect(ws.count).to eq(7)
54
+ expect(ws.count(text)).to eq(7)
59
55
  end
60
56
 
61
57
  it 'counts a hyperlink as one word in the word count' do
62
58
  text = 'The site address is http://www.example.com she said.'
63
59
  ws = WordCountAnalyzer::Counter.new(
64
- text: text,
65
60
  hyperlink: 'split_at_period',
66
61
  forward_slash: 'count_as_one'
67
62
  )
68
- expect(ws.count).to eq(9)
63
+ expect(ws.count(text)).to eq(9)
69
64
  end
70
65
 
71
66
  it 'does not search for hyperlinks' do
72
67
  text = 'The site address is http://www.example.com she said.'
73
68
  ws = WordCountAnalyzer::Counter.new(
74
- text: text,
75
69
  hyperlink: 'no_special_treatment'
76
70
  )
77
- expect(ws.count).to eq(8)
71
+ expect(ws.count(text)).to eq(8)
78
72
  end
79
73
 
80
74
  it 'sets count_as_one as the default option' do
81
75
  text = 'The site address is http://www.example.com she said.'
82
- ws = WordCountAnalyzer::Counter.new(text: text)
83
- expect(ws.count).to eq(7)
76
+ ws = WordCountAnalyzer::Counter.new
77
+ expect(ws.count(text)).to eq(7)
84
78
  end
85
79
  end
86
80
 
87
81
  context 'contraction' do
88
82
  it 'handles an invalid contraction argument value' do
89
83
  text = 'hello world.'
90
- ws = WordCountAnalyzer::Counter.new(text: text, contraction: 'hello')
91
- expect { ws.count }.to raise_error('The value you specified for contraction is not a valid option. Please use either `count_as_one` or `count_as_multiple`. The default option is `count_as_one`')
84
+ ws = WordCountAnalyzer::Counter.new(contraction: 'hello')
85
+ expect { ws.count(text) }.to raise_error('The value you specified for contraction is not a valid option. Please use either `count_as_one` or `count_as_multiple`. The default option is `count_as_one`')
92
86
  end
93
87
 
94
88
  it 'counts a contraction as one word in the word count' do
95
89
  text = "Don't do that."
96
90
  ws = WordCountAnalyzer::Counter.new(
97
- text: text,
98
91
  contraction: 'count_as_one'
99
92
  )
100
- expect(ws.count).to eq(3)
93
+ expect(ws.count(text)).to eq(3)
101
94
  end
102
95
 
103
96
  it 'splits a contraction into its separate words for the word count' do
104
97
  text = "Don't do that."
105
98
  ws = WordCountAnalyzer::Counter.new(
106
- text: text,
107
99
  contraction: 'count_as_multiple'
108
100
  )
109
- expect(ws.count).to eq(4)
101
+ expect(ws.count(text)).to eq(4)
110
102
  end
111
103
 
112
104
  it 'sets count_as_one as the default option' do
113
105
  text = "Don't do that."
114
- ws = WordCountAnalyzer::Counter.new(text: text)
115
- expect(ws.count).to eq(3)
106
+ ws = WordCountAnalyzer::Counter.new
107
+ expect(ws.count(text)).to eq(3)
116
108
  end
117
109
  end
118
110
 
119
111
  context 'hyphenated_word' do
120
112
  it 'handles an invalid hyphenated_word argument value' do
121
113
  text = 'hello world.'
122
- ws = WordCountAnalyzer::Counter.new(text: text, hyphenated_word: 'hello')
123
- expect { ws.count }.to raise_error('The value you specified for hyphenated_word is not a valid option. Please use either `count_as_one` or `count_as_multiple`. The default option is `count_as_one`')
114
+ ws = WordCountAnalyzer::Counter.new(hyphenated_word: 'hello')
115
+ expect { ws.count(text) }.to raise_error('The value you specified for hyphenated_word is not a valid option. Please use either `count_as_one` or `count_as_multiple`. The default option is `count_as_one`')
124
116
  end
125
117
 
126
118
  it 'counts a hyphenated word as one word in the word count' do
127
119
  text = 'He has a devil-may-care attitude.'
128
120
  ws = WordCountAnalyzer::Counter.new(
129
- text: text,
130
121
  hyphenated_word: 'count_as_one'
131
122
  )
132
- expect(ws.count).to eq(5)
123
+ expect(ws.count(text)).to eq(5)
133
124
  end
134
125
 
135
126
  it 'splits a hyphenated word into its separate words for the word count' do
136
127
  text = 'He has a devil-may-care attitude.'
137
128
  ws = WordCountAnalyzer::Counter.new(
138
- text: text,
139
129
  hyphenated_word: 'count_as_multiple'
140
130
  )
141
- expect(ws.count).to eq(7)
131
+ expect(ws.count(text)).to eq(7)
142
132
  end
143
133
 
144
134
  it 'sets count_as_one as the default option' do
145
135
  text = 'He has a devil-may-care attitude.'
146
- ws = WordCountAnalyzer::Counter.new(text: text)
147
- expect(ws.count).to eq(5)
136
+ ws = WordCountAnalyzer::Counter.new
137
+ expect(ws.count(text)).to eq(5)
148
138
  end
149
139
  end
150
140
 
151
141
  context 'date' do
152
142
  it 'handles an invalid date argument value' do
153
143
  text = 'hello world.'
154
- ws = WordCountAnalyzer::Counter.new(text: text, date: 'hello')
155
- expect { ws.count }.to raise_error('The value you specified for date is not a valid option. Please use either `count_as_one` or `no_special_treatment`. The default option is `no_special_treatment`')
144
+ ws = WordCountAnalyzer::Counter.new(date: 'hello')
145
+ expect { ws.count(text) }.to raise_error('The value you specified for date is not a valid option. Please use either `count_as_one` or `no_special_treatment`. The default option is `no_special_treatment`')
156
146
  end
157
147
 
158
148
  it 'ignores date placeables' do
159
149
  text = 'Today is Tues. March 3rd, 2011.'
160
150
  ws = WordCountAnalyzer::Counter.new(
161
- text: text,
162
151
  date: 'no_special_treatment'
163
152
  )
164
- expect(ws.count).to eq(6)
153
+ expect(ws.count(text)).to eq(6)
165
154
  end
166
155
 
167
156
  it 'counts a date placeable as one word in the word count' do
168
157
  text = 'Today is Tues. March 3rd, 2011.'
169
158
  ws = WordCountAnalyzer::Counter.new(
170
- text: text,
171
159
  date: 'count_as_one'
172
160
  )
173
- expect(ws.count).to eq(3)
161
+ expect(ws.count(text)).to eq(3)
174
162
  end
175
163
 
176
164
  it 'sets count_as_one as the default option' do
177
165
  text = 'Today is Tues. March 3rd, 2011.'
178
- ws = WordCountAnalyzer::Counter.new(text: text)
179
- expect(ws.count).to eq(6)
166
+ ws = WordCountAnalyzer::Counter.new
167
+ expect(ws.count(text)).to eq(6)
180
168
  end
181
169
  end
182
170
 
183
171
  context 'number' do
184
172
  it 'handles an invalid number argument value' do
185
173
  text = 'hello world.'
186
- ws = WordCountAnalyzer::Counter.new(text: text, number: 'hello')
187
- expect { ws.count }.to raise_error('The value you specified for number is not a valid option. Please use either `ignore` or `count`. The default option is `count`')
174
+ ws = WordCountAnalyzer::Counter.new(number: 'hello')
175
+ expect { ws.count(text) }.to raise_error('The value you specified for number is not a valid option. Please use either `ignore` or `count`. The default option is `count`')
188
176
  end
189
177
 
190
178
  it 'counts a number as a word' do
191
179
  text = 'There is $300 in the safe. The password is 1234.'
192
180
  ws = WordCountAnalyzer::Counter.new(
193
- text: text,
194
181
  number: 'count'
195
182
  )
196
- expect(ws.count).to eq(10)
183
+ expect(ws.count(text)).to eq(10)
197
184
  end
198
185
 
199
186
  it 'ignores numbers in the word count' do
200
187
  text = 'There is $300 in the safe. The password is 1234.'
201
188
  ws = WordCountAnalyzer::Counter.new(
202
- text: text,
203
189
  number: 'ignore'
204
190
  )
205
- expect(ws.count).to eq(8)
191
+ expect(ws.count(text)).to eq(8)
206
192
  end
207
193
 
208
194
  it 'sets count as the default option' do
209
195
  text = 'There is $300 in the safe. The password is 1234.'
210
- ws = WordCountAnalyzer::Counter.new(text: text)
211
- expect(ws.count).to eq(10)
196
+ ws = WordCountAnalyzer::Counter.new
197
+ expect(ws.count(text)).to eq(10)
212
198
  end
213
199
  end
214
200
 
215
201
  context 'number_list' do
216
202
  it 'handles an invalid number argument value' do
217
203
  text = 'hello world.'
218
- ws = WordCountAnalyzer::Counter.new(text: text, numbered_list: 'hello')
219
- expect { ws.count }.to raise_error('The value you specified for numbered_list is not a valid option. Please use either `ignore` or `count`. The default option is `count`')
204
+ ws = WordCountAnalyzer::Counter.new(numbered_list: 'hello')
205
+ expect { ws.count(text) }.to raise_error('The value you specified for numbered_list is not a valid option. Please use either `ignore` or `count`. The default option is `count`')
220
206
  end
221
207
 
222
208
  it 'counts a numbered list number as a word' do
223
209
  text = "Number 2. Add a list 1. List item a\n\n2. List item b\n\n3. List item c."
224
210
  ws = WordCountAnalyzer::Counter.new(
225
- text: text,
226
211
  numbered_list: 'count'
227
212
  )
228
- expect(ws.count).to eq(17)
213
+ expect(ws.count(text)).to eq(17)
229
214
  end
230
215
 
231
216
  it 'ignores numbered list numbers' do
232
217
  text = "Number 2. Add a list 1. List item a\n\n2. List item b\n\n3. List item c."
233
218
  ws = WordCountAnalyzer::Counter.new(
234
- text: text,
235
219
  numbered_list: 'ignore'
236
220
  )
237
- expect(ws.count).to eq(14)
221
+ expect(ws.count(text)).to eq(14)
238
222
  end
239
223
 
240
224
  it 'sets count as the default option' do
241
225
  text = "Number 2. Add a list 1. List item a\n\n2. List item b\n\n3. List item c."
242
- ws = WordCountAnalyzer::Counter.new(text: text)
243
- expect(ws.count).to eq(17)
226
+ ws = WordCountAnalyzer::Counter.new
227
+ expect(ws.count(text)).to eq(17)
244
228
  end
245
229
  end
246
230
 
247
231
  context 'xhtml' do
248
232
  it 'handles an invalid number argument value' do
249
233
  text = 'hello world.'
250
- ws = WordCountAnalyzer::Counter.new(text: text, xhtml: 'hello')
251
- expect { ws.count }.to raise_error('The value you specified for xhtml is not a valid option. Please use either `remove` or `keep`. The default option is `remove`')
234
+ ws = WordCountAnalyzer::Counter.new(xhtml: 'hello')
235
+ expect { ws.count(text) }.to raise_error('The value you specified for xhtml is not a valid option. Please use either `remove` or `keep`. The default option is `remove`')
252
236
  end
253
237
 
254
238
  it 'removes all xhtml from the text' do
255
239
  text = "<span class='orange-text'>Hello world</span>"
256
240
  ws = WordCountAnalyzer::Counter.new(
257
- text: text,
258
241
  xhtml: 'remove'
259
242
  )
260
- expect(ws.count).to eq(2)
243
+ expect(ws.count(text)).to eq(2)
261
244
  end
262
245
 
263
246
  it 'keeps xhtml in the text' do
264
247
  text = "<span class='orange-text'>Hello world</span>"
265
248
  ws = WordCountAnalyzer::Counter.new(
266
- text: text,
267
249
  xhtml: 'keep',
268
250
  forward_slash: 'count_as_one'
269
251
  )
270
- expect(ws.count).to eq(3)
252
+ expect(ws.count(text)).to eq(3)
271
253
  end
272
254
 
273
255
  it 'keeps xhtml in the text' do
274
256
  text = "<span class='orange-text'>Hello world</span>"
275
257
  ws = WordCountAnalyzer::Counter.new(
276
- text: text,
277
258
  xhtml: 'keep'
278
259
  )
279
- expect(ws.count).to eq(4)
260
+ expect(ws.count(text)).to eq(4)
280
261
  end
281
262
 
282
263
  it 'sets remove as the default option' do
283
264
  text = "<span class='orange-text'>Hello world</span>"
284
- ws = WordCountAnalyzer::Counter.new(text: text)
285
- expect(ws.count).to eq(2)
265
+ ws = WordCountAnalyzer::Counter.new
266
+ expect(ws.count(text)).to eq(2)
286
267
  end
287
268
  end
288
269
 
289
270
  context 'forward_slash' do
290
271
  it 'handles an invalid number argument value' do
291
272
  text = 'hello world.'
292
- ws = WordCountAnalyzer::Counter.new(text: text, forward_slash: 'hello')
293
- expect { ws.count }.to raise_error('The value you specified for forward_slash is not a valid option. Please use either `count_as_one`, `count_as_multiple` or `count_as_multiple_except_dates`. The default option is `count_as_multiple_except_dates`')
273
+ ws = WordCountAnalyzer::Counter.new(forward_slash: 'hello')
274
+ expect { ws.count(text) }.to raise_error('The value you specified for forward_slash is not a valid option. Please use either `count_as_one`, `count_as_multiple` or `count_as_multiple_except_dates`. The default option is `count_as_multiple_except_dates`')
294
275
  end
295
276
 
296
277
  it 'counts a forward slash as multiple words (except dates) #001' do
297
278
  text = "She/he/it said hello. 4/22/2013."
298
279
  ws = WordCountAnalyzer::Counter.new(
299
- text: text,
300
280
  forward_slash: 'count_as_multiple_except_dates'
301
281
  )
302
- expect(ws.count).to eq(6)
282
+ expect(ws.count(text)).to eq(6)
303
283
  end
304
284
 
305
285
  it 'counts a forward slash as multiple words #002' do
306
286
  text = "She/he/it said hello. 4/22/2013."
307
287
  ws = WordCountAnalyzer::Counter.new(
308
- text: text,
309
288
  forward_slash: 'count_as_multiple'
310
289
  )
311
- expect(ws.count).to eq(8)
290
+ expect(ws.count(text)).to eq(8)
312
291
  end
313
292
 
314
293
  it 'counts a forward slash as multiple words #003' do
315
294
  text = "She/he/it said hello. 4/22/2013."
316
295
  ws = WordCountAnalyzer::Counter.new(
317
- text: text,
318
296
  forward_slash: 'count_as_multiple',
319
297
  date: 'count_as_one'
320
298
  )
321
- expect(ws.count).to eq(6)
299
+ expect(ws.count(text)).to eq(6)
322
300
  end
323
301
 
324
302
  it 'counts a forward slash as one word' do
325
303
  text = "She/he/it said hello."
326
304
  ws = WordCountAnalyzer::Counter.new(
327
- text: text,
328
305
  forward_slash: 'count_as_one'
329
306
  )
330
- expect(ws.count).to eq(3)
307
+ expect(ws.count(text)).to eq(3)
331
308
  end
332
309
 
333
310
  it 'sets count_as_multiple_except_dates as the default option' do
334
311
  text = "She/he/it said hello. 4/22/2013."
335
- ws = WordCountAnalyzer::Counter.new(text: text)
336
- expect(ws.count).to eq(6)
312
+ ws = WordCountAnalyzer::Counter.new
313
+ expect(ws.count(text)).to eq(6)
337
314
  end
338
315
  end
339
316
 
340
317
  context 'backslash' do
341
318
  it 'handles an invalid number argument value' do
342
319
  text = 'hello world.'
343
- ws = WordCountAnalyzer::Counter.new(text: text, backslash: 'hello')
344
- expect { ws.count }.to raise_error('The value you specified for backslash is not a valid option. Please use either `count_as_one` or `count_as_multiple`. The default option is `count_as_one`')
320
+ ws = WordCountAnalyzer::Counter.new(backslash: 'hello')
321
+ expect { ws.count(text) }.to raise_error('The value you specified for backslash is not a valid option. Please use either `count_as_one` or `count_as_multiple`. The default option is `count_as_one`')
345
322
  end
346
323
 
347
324
  it 'counts a token with backslashes as one word' do
348
325
  text = 'The file location is c:\Users\johndoe'
349
326
  ws = WordCountAnalyzer::Counter.new(
350
- text: text,
351
327
  backslash: 'count_as_one'
352
328
  )
353
- expect(ws.count).to eq(5)
329
+ expect(ws.count(text)).to eq(5)
354
330
  end
355
331
 
356
332
  it 'counts a token with backslashes as multiple words' do
357
333
  text = 'The file location is c:\Users\johndoe'
358
334
  ws = WordCountAnalyzer::Counter.new(
359
- text: text,
360
335
  backslash: 'count_as_multiple'
361
336
  )
362
- expect(ws.count).to eq(7)
337
+ expect(ws.count(text)).to eq(7)
363
338
  end
364
339
 
365
340
  it 'sets count_as_one as the default option' do
366
341
  text = 'The file location is c:\Users\johndoe'
367
- ws = WordCountAnalyzer::Counter.new(text: text)
368
- expect(ws.count).to eq(5)
342
+ ws = WordCountAnalyzer::Counter.new
343
+ expect(ws.count(text)).to eq(5)
369
344
  end
370
345
  end
371
346
 
372
347
  context 'dotted_line' do
373
348
  it 'handles an invalid number argument value' do
374
349
  text = 'hello world.'
375
- ws = WordCountAnalyzer::Counter.new(text: text, dotted_line: 'hello')
376
- expect { ws.count }.to raise_error('The value you specified for dotted_line is not a valid option. Please use either `ignore` or `count`. The default option is `ignore`')
350
+ ws = WordCountAnalyzer::Counter.new(dotted_line: 'hello')
351
+ expect { ws.count(text) }.to raise_error('The value you specified for dotted_line is not a valid option. Please use either `ignore` or `count`. The default option is `ignore`')
377
352
  end
378
353
 
379
354
  it 'ignores continuous strings of dots in the word count' do
380
355
  text = 'Here is one …………………………………………………………………… and another ......'
381
356
  ws = WordCountAnalyzer::Counter.new(
382
- text: text,
383
357
  dotted_line: 'ignore'
384
358
  )
385
- expect(ws.count).to eq(5)
359
+ expect(ws.count(text)).to eq(5)
386
360
  end
387
361
 
388
362
  it 'counts a continuous string of dots as a word' do
389
363
  text = 'Here is one …………………………………………………………………… and another ......'
390
364
  ws = WordCountAnalyzer::Counter.new(
391
- text: text,
392
365
  dotted_line: 'count'
393
366
  )
394
- expect(ws.count).to eq(7)
367
+ expect(ws.count(text)).to eq(7)
395
368
  end
396
369
 
397
370
  it 'sets ignore as the default option' do
398
371
  text = 'Here is one …………………………………………………………………… and another ......'
399
- ws = WordCountAnalyzer::Counter.new(text: text)
400
- expect(ws.count).to eq(5)
372
+ ws = WordCountAnalyzer::Counter.new
373
+ expect(ws.count(text)).to eq(5)
401
374
  end
402
375
  end
403
376
 
404
377
  context 'dashed_line' do
405
378
  it 'handles an invalid number argument value' do
406
379
  text = 'hello world.'
407
- ws = WordCountAnalyzer::Counter.new(text: text, dashed_line: 'hello')
408
- expect { ws.count }.to raise_error('The value you specified for dashed_line is not a valid option. Please use either `ignore` or `count`. The default option is `ignore`')
380
+ ws = WordCountAnalyzer::Counter.new(dashed_line: 'hello')
381
+ expect { ws.count(text) }.to raise_error('The value you specified for dashed_line is not a valid option. Please use either `ignore` or `count`. The default option is `ignore`')
409
382
  end
410
383
 
411
384
  it 'ignores continuous strings of dashes in the word count' do
412
385
  text = 'Here is one ----- and another -----'
413
386
  ws = WordCountAnalyzer::Counter.new(
414
- text: text,
415
387
  dashed_line: 'ignore'
416
388
  )
417
- expect(ws.count).to eq(5)
389
+ expect(ws.count(text)).to eq(5)
418
390
  end
419
391
 
420
392
  it 'counts a continuous string of dashes as a word' do
421
393
  text = 'Here is one ----- and another -----'
422
394
  ws = WordCountAnalyzer::Counter.new(
423
- text: text,
424
395
  dashed_line: 'count'
425
396
  )
426
- expect(ws.count).to eq(7)
397
+ expect(ws.count(text)).to eq(7)
427
398
  end
428
399
 
429
400
  it 'sets ignore as the default option' do
430
401
  text = 'Here is one ----- and another -----'
431
- ws = WordCountAnalyzer::Counter.new(text: text)
432
- expect(ws.count).to eq(5)
402
+ ws = WordCountAnalyzer::Counter.new
403
+ expect(ws.count(text)).to eq(5)
433
404
  end
434
405
  end
435
406
 
436
407
  context 'underscore' do
437
408
  it 'handles an invalid number argument value' do
438
409
  text = 'hello world.'
439
- ws = WordCountAnalyzer::Counter.new(text: text, underscore: 'hello')
440
- expect { ws.count }.to raise_error('The value you specified for underscore is not a valid option. Please use either `ignore` or `count`. The default option is `ignore`')
410
+ ws = WordCountAnalyzer::Counter.new(underscore: 'hello')
411
+ expect { ws.count(text) }.to raise_error('The value you specified for underscore is not a valid option. Please use either `ignore` or `count`. The default option is `ignore`')
441
412
  end
442
413
 
443
414
  it 'ignores continuous strings of underscores in the word count' do
444
415
  text = "Here is one ______ and another ______"
445
416
  ws = WordCountAnalyzer::Counter.new(
446
- text: text,
447
417
  underscore: 'ignore'
448
418
  )
449
- expect(ws.count).to eq(5)
419
+ expect(ws.count(text)).to eq(5)
450
420
  end
451
421
 
452
422
  it 'counts a continuous string of underscores as a word' do
453
423
  text = 'Here is one ______ and another ______'
454
424
  ws = WordCountAnalyzer::Counter.new(
455
- text: text,
456
425
  underscore: 'count'
457
426
  )
458
- expect(ws.count).to eq(7)
427
+ expect(ws.count(text)).to eq(7)
459
428
  end
460
429
 
461
430
  it 'sets ignore as the default option' do
462
431
  text = 'Here is one ______ and another ______'
463
- ws = WordCountAnalyzer::Counter.new(text: text)
464
- expect(ws.count).to eq(5)
432
+ ws = WordCountAnalyzer::Counter.new
433
+ expect(ws.count(text)).to eq(5)
465
434
  end
466
435
  end
467
436
 
468
437
  context 'stray_punctuation' do
469
438
  it 'handles an invalid number argument value' do
470
439
  text = 'hello world.'
471
- ws = WordCountAnalyzer::Counter.new(text: text, stray_punctuation: 'hello')
472
- expect { ws.count }.to raise_error('The value you specified for stray_punctuation is not a valid option. Please use either `ignore` or `count`. The default option is `ignore`')
440
+ ws = WordCountAnalyzer::Counter.new(stray_punctuation: 'hello')
441
+ expect { ws.count(text) }.to raise_error('The value you specified for stray_punctuation is not a valid option. Please use either `ignore` or `count`. The default option is `ignore`')
473
442
  end
474
443
 
475
444
  it 'ignores continuous strings of underscores in the word count' do
476
445
  text = 'Hello world ? This is another - sentence .'
477
446
  ws = WordCountAnalyzer::Counter.new(
478
- text: text,
479
447
  stray_punctuation: 'ignore'
480
448
  )
481
- expect(ws.count).to eq(6)
449
+ expect(ws.count(text)).to eq(6)
482
450
  end
483
451
 
484
452
  it 'counts a continuous string of underscores as a word' do
485
453
  text = 'Hello world ? This is another - sentence .'
486
454
  ws = WordCountAnalyzer::Counter.new(
487
- text: text,
488
455
  stray_punctuation: 'count'
489
456
  )
490
- expect(ws.count).to eq(9)
457
+ expect(ws.count(text)).to eq(9)
491
458
  end
492
459
 
493
460
  it 'sets ignore as the default option' do
494
461
  text = 'Hello world ? This is another - sentence .'
495
- ws = WordCountAnalyzer::Counter.new(text: text)
496
- expect(ws.count).to eq(6)
462
+ ws = WordCountAnalyzer::Counter.new
463
+ expect(ws.count(text)).to eq(6)
497
464
  end
498
465
  end
499
466
 
500
467
  it 'counts the words in a string #001' do
501
468
  text = "This string has a date: Monday, November 3rd, 2011. I was thinking... it also shouldn't have too many contractions, maybe 2. <html> Some HTML and a hyphenated-word</html>. Don't count punctuation ? ? ? Please visit the ____________ ------------ ........ go-to site: https://www.example-site.com today. Let's add a list 1. item a 2. item b 3. item c. Now let's add he/she/it or a c:\\Users\\john. 2/15/2012 is the date! { HYPERLINK 'http://www.hello.com' }"
502
469
  ws = WordCountAnalyzer::Counter.new(
503
- text: text,
504
470
  ellipsis: 'ignore',
505
471
  hyperlink: 'count_as_one',
506
472
  contraction: 'count_as_one',
@@ -516,13 +482,12 @@ RSpec.describe WordCountAnalyzer::Counter do
516
482
  underscore: 'ignore',
517
483
  stray_punctuation: 'ignore'
518
484
  )
519
- expect(ws.count).to eq(62)
485
+ expect(ws.count(text)).to eq(62)
520
486
  end
521
487
 
522
488
  it 'counts the words in a string #002' do
523
489
  text = "This string has a date: Monday, November 3rd, 2011. I was thinking... it also shouldn't have too many contractions, maybe 2. <html> Some HTML and a hyphenated-word</html>. Don't count punctuation ? ? ? Please visit the ____________ ------------ ........ go-to site: https://www.example-site.com today. Let's add a list 1. item a 2. item b 3. item c. Now let's add he/she/it or a c:\\Users\\john. 2/15/2012 is the date! { HYPERLINK 'http://www.hello.com' }"
524
490
  ws = WordCountAnalyzer::Counter.new(
525
- text: text,
526
491
  ellipsis: 'no_special_treatment',
527
492
  hyperlink: 'no_special_treatment',
528
493
  contraction: 'count_as_multiple',
@@ -538,32 +503,31 @@ RSpec.describe WordCountAnalyzer::Counter do
538
503
  underscore: 'count',
539
504
  stray_punctuation: 'count'
540
505
  )
541
- expect(ws.count).to eq(77)
506
+ expect(ws.count(text)).to eq(77)
542
507
  end
543
508
 
544
509
  it 'counts the words in a string #003' do
545
510
  text = "This string has a date: Monday, November 3rd, 2011. I was thinking... it also shouldn't have too many contractions, maybe 2. <html> Some HTML and a hyphenated-word</html>. Don't count punctuation ? ? ? Please visit the ____________ ------------ ........ go-to site: https://www.example-site.com today. Let's add a list 1. item a 2. item b 3. item c. Now let's add he/she/it or a c:\\Users\\john. 2/15/2012 is the date! { HYPERLINK 'http://www.hello.com' }"
546
- ws = WordCountAnalyzer::Counter.new(text: text)
547
- expect(ws.count).to eq(64)
511
+ ws = WordCountAnalyzer::Counter.new
512
+ expect(ws.count(text)).to eq(64)
548
513
  end
549
514
 
550
515
  it 'counts the words in a string #004' do
551
516
  text = "This string has a date: Monday, November 3rd, 2011. I was thinking... it also shouldn't have too many contractions, maybe 2. <html> Some HTML and a hyphenated-word</html>. Don't count punctuation ? ? ? Please visit the ____________ ------------ ........ go-to site: https://www.example-site.com today. Let's add a list 1. item a 2. item b 3. item c. Now let's add he/she/it or a c:\\Users\\john. 2/15/2012 is the date! { HYPERLINK 'http://www.hello.com' }"
552
- ws = WordCountAnalyzer::Counter.new(text: text, forward_slash: 'count_as_multiple')
553
- expect(ws.count).to eq(66)
517
+ ws = WordCountAnalyzer::Counter.new(forward_slash: 'count_as_multiple')
518
+ expect(ws.count(text)).to eq(66)
554
519
  end
555
520
 
556
521
  it 'counts the words in a string #005' do
557
522
  text = "Hello world... 11/22/2013"
558
- ws = WordCountAnalyzer::Counter.new(text: text)
559
- expect(ws.count).to eq(3)
523
+ ws = WordCountAnalyzer::Counter.new
524
+ expect(ws.count(text)).to eq(3)
560
525
  end
561
526
 
562
527
  context 'Pages Word Count' do
563
528
  it 'reverse engineers Pages word count #001' do
564
529
  text = "This string has a date: Monday, November 3rd, 2011. I was thinking... it also shouldn't have too many contractions, maybe 2. <html> Some HTML and a hyphenated-word</html>. Don't count punctuation ? ? ? Please visit the ____________ ------------ ........ go-to site: https://www.example-site.com today. Let's add a list \n\n1. item a \n\n2. item b \n\n3. item c. Now let's add he/she/it or a c:\\Users\\john. 2/15/2012 is the date! { HYPERLINK 'http://www.hello.com' }"
565
530
  ws = WordCountAnalyzer::Counter.new(
566
- text: text,
567
531
  ellipsis: 'no_special_treatment',
568
532
  hyperlink: 'split_at_period',
569
533
  contraction: 'count_as_one',
@@ -579,31 +543,31 @@ RSpec.describe WordCountAnalyzer::Counter do
579
543
  underscore: 'ignore',
580
544
  stray_punctuation: 'ignore'
581
545
  )
582
- expect(ws.count).to eq(76)
546
+ expect(ws.count(text)).to eq(76)
583
547
  end
584
548
 
585
549
  it 'reverse engineers Pages word count #002' do
586
550
  text = "This string has a date: Monday, November 3rd, 2011. I was thinking... it also shouldn't have too many contractions, maybe 2. <html> Some HTML and a hyphenated-word</html>. Don't count punctuation ? ? ? Please visit the ____________ ------------ ........ go-to site: https://www.example-site.com today. Let's add a list 1. item a 2. item b 3. item c. Now let's add he/she/it or a c:\\Users\\john. 2/15/2012 is the date! { HYPERLINK 'http://www.hello.com' }"
587
- ws = WordCountAnalyzer::Counter.new(text: text)
588
- expect(ws.pages_count).to eq(76)
551
+ ws = WordCountAnalyzer::Counter.new
552
+ expect(ws.pages_count(text)).to eq(76)
589
553
  end
590
554
 
591
555
  it 'reverse engineers Pages word count #003' do
592
556
  text = "..."
593
- ws = WordCountAnalyzer::Counter.new(text: text)
594
- expect(ws.pages_count).to eq(0)
557
+ ws = WordCountAnalyzer::Counter.new
558
+ expect(ws.pages_count(text)).to eq(0)
595
559
  end
596
560
 
597
561
  it 'reverse engineers Pages word count #004' do
598
562
  text = "1. List item a\n\n2. List item b\n\n3. List item c"
599
- ws = WordCountAnalyzer::Counter.new(text: text)
600
- expect(ws.pages_count).to eq(9)
563
+ ws = WordCountAnalyzer::Counter.new
564
+ expect(ws.pages_count(text)).to eq(9)
601
565
  end
602
566
 
603
567
  it 'reverse engineers Pages word count #005' do
604
568
  text = "<span class=\"large-text\">Hello world</span> <new-tag>Hello</new-tag>"
605
- ws = WordCountAnalyzer::Counter.new(text: text)
606
- expect(ws.pages_count).to eq(12)
569
+ ws = WordCountAnalyzer::Counter.new
570
+ expect(ws.pages_count(text)).to eq(12)
607
571
  end
608
572
  end
609
573
 
@@ -611,7 +575,6 @@ RSpec.describe WordCountAnalyzer::Counter do
611
575
  it 'reverse engineers the Microsoft Word / wc (Unix) word count #001' do
612
576
  text = "This string has a date: Monday, November 3rd, 2011. I was thinking... it also shouldn't have too many contractions, maybe 2. <html> Some HTML and a hyphenated-word</html>. Don't count punctuation ? ? ? Please visit the ____________ ------------ ........ go-to site: https://www.example-site.com today. Let's add a list 1. item a 2. item b 3. item c. Now let's add he/she/it or a c:\\Users\\john. 2/15/2012 is the date! { HYPERLINK 'http://www.hello.com' }"
613
577
  ws = WordCountAnalyzer::Counter.new(
614
- text: text,
615
578
  ellipsis: 'no_special_treatment',
616
579
  hyperlink: 'count_as_one',
617
580
  contraction: 'count_as_one',
@@ -627,50 +590,50 @@ RSpec.describe WordCountAnalyzer::Counter do
627
590
  underscore: 'count',
628
591
  stray_punctuation: 'count'
629
592
  )
630
- expect(ws.count).to eq(71)
593
+ expect(ws.count(text)).to eq(71)
631
594
  end
632
595
 
633
596
  it 'reverse engineers the Microsoft Word / wc (Unix) word count #002' do
634
597
  text = "This string has a date: Monday, November 3rd, 2011. I was thinking... it also shouldn't have too many contractions, maybe 2. <html> Some HTML and a hyphenated-word</html>. Don't count punctuation ? ? ? Please visit the ____________ ------------ ........ go-to site: https://www.example-site.com today. Let's add a list 1. item a 2. item b 3. item c. Now let's add he/she/it or a c:\\Users\\john. 2/15/2012 is the date! { HYPERLINK 'http://www.hello.com' }"
635
- ws = WordCountAnalyzer::Counter.new(text: text)
636
- expect(ws.mword_count).to eq(71)
598
+ ws = WordCountAnalyzer::Counter.new
599
+ expect(ws.mword_count(text)).to eq(71)
637
600
  end
638
601
  end
639
602
 
640
603
  context 'example sentences' do
641
604
  it 'String with common words (no edge cases) #001' do
642
- ws = WordCountAnalyzer::Counter.new(text: 'This sentence contains nothing crazy.')
643
- expect(ws.count).to eq(5)
605
+ ws = WordCountAnalyzer::Counter.new
606
+ expect(ws.count('This sentence contains nothing crazy.')).to eq(5)
644
607
  end
645
608
 
646
609
  it 'String with a number #002' do
647
- ws = WordCountAnalyzer::Counter.new(text: 'This sentence contains 1 number.')
648
- expect(ws.count).to eq(5)
610
+ ws = WordCountAnalyzer::Counter.new
611
+ expect(ws.count('This sentence contains 1 number.')).to eq(5)
649
612
  end
650
613
 
651
614
  it 'String with a date #003' do
652
- ws = WordCountAnalyzer::Counter.new(text: 'Today is Monday, April 4th, 2011.')
653
- expect(ws.count).to eq(6)
615
+ ws = WordCountAnalyzer::Counter.new
616
+ expect(ws.count('Today is Monday, April 4th, 2011.')).to eq(6)
654
617
  end
655
618
 
656
619
  it 'String #004' do
657
- ws = WordCountAnalyzer::Counter.new(text: 'hello world ...')
658
- expect(ws.count).to eq(2)
620
+ ws = WordCountAnalyzer::Counter.new
621
+ expect(ws.count('hello world ...')).to eq(2)
659
622
  end
660
623
 
661
624
  it 'does not split on unicode chars' do
662
- ws = WordCountAnalyzer::Counter.new(text: 'São Paulo')
663
- expect(ws.count).to eq(2)
625
+ ws = WordCountAnalyzer::Counter.new
626
+ expect(ws.count('São Paulo')).to eq(2)
664
627
  end
665
628
 
666
629
  it 'should not count HTML tags' do
667
- ws = WordCountAnalyzer::Counter.new(text: "<a href=\"http://thefamousfox.com\">the brown fox</a> jumped over the lazy dog")
668
- expect(ws.count).to eq(8)
630
+ ws = WordCountAnalyzer::Counter.new
631
+ expect(ws.count("<a href=\"http://thefamousfox.com\">the brown fox</a> jumped over the lazy dog")).to eq(8)
669
632
  end
670
633
 
671
634
  it 'should handle special characters' do
672
- ws = WordCountAnalyzer::Counter.new(text: "the \"brown\" fox 'jumped' | over \\ the / lazy dog")
673
- expect(ws.count).to eq(8)
635
+ ws = WordCountAnalyzer::Counter.new
636
+ expect(ws.count("the \"brown\" fox 'jumped' | over \\ the / lazy dog")).to eq(8)
674
637
  end
675
638
  end
676
639
  end