wordini 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/wordini.rb +9 -2
  2. data/spec/wordini_spec.rb +65 -32
  3. metadata +1 -1
data/lib/wordini.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Wordini
2
2
 
3
3
  def self.obfuscate(word_string, words_to_remove)
4
- split_words = word_string.split.map{ |word|
4
+ word_string.split.map{ |word|
5
5
  if words_to_remove.include? word
6
6
  word = "*" * word.split('').count
7
7
  else
@@ -10,5 +10,12 @@ class Wordini
10
10
  }.join(' ')
11
11
  end
12
12
 
13
- #puts self.obfuscate("This is the most awesome way to run some awesome game", ["This", "awesome", "fun", "the"])
13
+ def self.report(word_string, search_terms)
14
+ word_set = {}
15
+ search_terms.each { |word|
16
+ count = word_string.split.count(word)
17
+ word_set[word] = count
18
+ }
19
+ word_set
20
+ end
14
21
  end
data/spec/wordini_spec.rb CHANGED
@@ -1,50 +1,83 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Wordini do
4
- describe "#obfuscator" do
4
+ describe "#obfuscate" do
5
5
 
6
- before(:each) do
7
- @word_string = "this string is an awesome string"
8
- @words_to_remove = ["this", "is", "not", "a", "string"]
9
- end
6
+ describe "when testing a one word string" do
7
+ it 'matches the word count' do
8
+ Wordini.obfuscate("doughnut", ["doughnut"]).split.count.should == 1
9
+ end
10
10
 
11
- it "takes a string as the first argument" do
12
- Wordini.obfuscate(@word_string, @words_to_remove)
13
- @word_string.should be_an_instance_of(String)
14
- end
11
+ it 'matches the word length' do
12
+ Wordini.obfuscate("doughnut", ["doughnut"]).length.should == 8
13
+ end
15
14
 
16
- it "takes an string or array as the second argument" do
17
- Wordini.obfuscate(@word_string, @words_to_remove)
18
- @words_to_remove.should be_an_instance_of(Array)
19
15
  end
20
16
 
21
- it "does not take other first arguments besides a string" do
22
- @word_string = ["cow"]
23
- lambda {Wordini.obfuscate(@word_string, @words_to_remove)}.should raise_error
24
- end
17
+ describe "when testing a two word string" do
18
+ it 'matches the word count' do
19
+ Wordini.obfuscate("red velvet", ["doughnut"]).split.count.should == 2
20
+ end
25
21
 
26
- it "does not take other second arguments besides an array or string" do
27
- @words_to_remove = 8
28
- lambda {Wordini.obfuscate(@word_string, @words_to_remove)}.should raise_error
22
+ it 'matches the word length including spaces' do
23
+ Wordini.obfuscate("red velvet", ["doughnut"]).length.should == 10
24
+ end
29
25
  end
30
26
 
31
- it "maintains the same number of 'words' in string" do
32
- new_string = Wordini.obfuscate(@word_string, @words_to_remove)
33
- new_string.split.count.should == 6
27
+ describe "maintains the integrity of the string" do
28
+ it 'matches the word count' do
29
+ Wordini.obfuscate("a b c d e", ["doughnut"]).split.count.should == 5
30
+ end
31
+
32
+ it 'matches the word length including spaces' do
33
+ Wordini.obfuscate("a b c d e", ["doughnut"]).length.should == 9
34
+ end
35
+
36
+ it "replaces the chosen words with * maintaining correct spacing" do
37
+ new_string = Wordini.obfuscate("I ate five doughnuts today", ["doughnuts", "ate"])
38
+ new_string.gsub("*", "").length.should == 14
39
+ end
40
+
41
+ it "contains replaced words with equivalent * count for word_char" do
42
+ new_string = Wordini.obfuscate("I ate five doughnuts today", ["doughnuts", "ate"])
43
+ new_string.count('*').should == 12
44
+ end
34
45
  end
46
+ end
47
+
48
+ describe "#report" do
49
+ describe "when searching for one word" do
50
+ it 'returns a hash' do
51
+ Wordini.report("I ate five doughnuts today", ["five"]).should be_an_instance_of(Hash)
52
+ end
53
+
54
+ it 'returns a key that matches the search term' do
55
+ word_hash = Wordini.report("I ate five doughnuts today", ["five"])
56
+ word_hash.keys[0].should == "five"
57
+ end
35
58
 
36
- it "replaces the chosen words with *" do
37
- new_string = Wordini.obfuscate(@word_string, @words_to_remove)
38
- split_array = new_string.split('')
39
- remaining_char = split_array - ["*"]
40
- remaining_char.count.should == 14
59
+ it 'returns a value that matches the frequency of the word' do
60
+ word_hash = Wordini.report("I ate five doughnuts today", ["five"])
61
+ word_hash.values[0].should == 1
62
+ end
41
63
  end
42
64
 
43
- it "contains replaced words with equivalent * count for word_char" do
44
- new_string = Wordini.obfuscate(@word_string, @words_to_remove)
45
- split_array = new_string.split('')
46
- count = split_array.select{ |star| star == '*' }.size
47
- count.should == 18
65
+ describe "when searching for multiple words" do
66
+ it 'returns a key that matches the search term' do
67
+ word_hash = Wordini.report("I ate five doughnuts today", ["five", "doughnuts", "three"])
68
+ puts word_hash
69
+ word_hash.keys.should == ["five", "doughnuts", "three"]
70
+ end
71
+
72
+ it 'returns a value that matches the frequency of the word' do
73
+ word_hash = Wordini.report("I ate five doughnuts today five times", ["five", "doughnuts", "three"])
74
+ word_hash.values.should == [2, 1, 0]
75
+ end
76
+
77
+ it 'returns a hash with correct key => value pairs' do
78
+ word_hash = Wordini.report("I ate five doughnuts today five times", ["five", "doughnuts", "three"])
79
+ word_hash.should == {"five" => 2, "doughnuts" => 1, "three" => 0}
80
+ end
48
81
  end
49
82
  end
50
83
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordini
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: