contador 1.2.0 → 2.0.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 2.0.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "contador"
8
- s.version = "1.2.0"
8
+ s.version = "2.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ivan Acosta-Rubio"]
12
- s.date = "2012-11-14"
12
+ s.date = "2012-12-07"
13
13
  s.description = "This gem counts the numbers of words in a string. It returns each word and the multiplicity"
14
14
  s.email = "ivan@bakedweb.net"
15
15
  s.extra_rdoc_files = [
@@ -1,11 +1,22 @@
1
+ class SimpleSplitter
2
+ attr_accessor :ingredients
3
+
4
+ def split
5
+ ingredients.split(" ")
6
+ end
7
+ end
8
+
9
+
10
+
1
11
  class Contador
2
12
 
3
- attr_accessor :string
13
+ attr_accessor :string, :splitter
4
14
 
5
- def initialize(string)
15
+ def initialize(string, splitter=SimpleSplitter)
6
16
  @omit = []
7
17
  @string = string
8
18
  @final = Hash.new
19
+ @splitter = splitter
9
20
  split_string_into_hash
10
21
  delete_omits if $omits
11
22
  end
@@ -24,13 +35,18 @@ class Contador
24
35
  @final.delete(word)
25
36
  end
26
37
 
38
+
27
39
  private
28
40
 
29
41
  def split_string_into_hash
30
- string.split(' ').each do |word|
42
+ s = @splitter.new
43
+ s.ingredients = string
44
+
45
+
46
+ s.split.each do |word|
31
47
  begin
32
48
  word.gsub!(/[^0-9A-Za-z[-]_\s]/, '')
33
- key = word.downcase
49
+ key = word.downcase.strip
34
50
  if @final.has_key?(key)
35
51
  @final[key] += 1
36
52
  else
@@ -45,7 +45,7 @@ describe Contador do
45
45
 
46
46
  end
47
47
 
48
- describe Contador, "No sally words" do
48
+ describe Contador, "No silly words" do
49
49
  it "omits some basic words" do
50
50
  contador = Contador.new("y y y precio")
51
51
  contador.omit("y")
@@ -64,3 +64,27 @@ describe Contador, "No sally words" do
64
64
  contador.multiplicity.should == {"precio" => 1}
65
65
  end
66
66
  end
67
+
68
+
69
+
70
+ describe Contador, "can be injected how to split words" do
71
+
72
+ it "splits words by commas" do
73
+
74
+ class CommaSplitter
75
+ attr_accessor :ingredients
76
+
77
+ def split
78
+ ingredients.split(",")
79
+ end
80
+ end
81
+
82
+
83
+ contador = Contador.new("protein shake, coffee", CommaSplitter)
84
+ contador.multiplicity.should == {"protein shake" => 1, "coffee" => 1}
85
+ end
86
+
87
+
88
+ end
89
+
90
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contador
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-14 00:00:00.000000000 Z
12
+ date: 2012-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  segments:
116
116
  - 0
117
- hash: -1571854133693256542
117
+ hash: 904274256159795146
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements: