contador 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,11 +6,22 @@ It a way to count the amount of times each word appears on a string.
6
6
  USAGE
7
7
  -----
8
8
 
9
- `@sentence = Tally.new("Tally is cool.")`
9
+ `@sentence = Contador.new("Tally is cool.")`
10
10
 
11
- `=> #<Tally:0x10103f488 @final={:is=>1, :cool=>1, :tally=>1}, @string="Tally is cool.">`
11
+ `=> #<Contador:0x10103f488 @final={:is=>1, :cool=>1, :tally=>1}, @string="Tally is cool.">`
12
12
 
13
13
  `@sentence.multiplicity`
14
14
 
15
15
  `=> {:is=>1, :cool=>1, :tally=>1}`
16
16
 
17
+ OMITING REQUENT WORDS
18
+ ----------------------
19
+
20
+ We use a global for omiting frequent words. For example:
21
+
22
+ `$omit = "yo no"`
23
+
24
+
25
+
26
+
27
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 1.0.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{contador}
8
- s.version = "0.2.0"
8
+ s.version = "1.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 = %q{2010-11-20}
12
+ s.date = %q{2011-03-31}
13
13
  s.description = %q{This gem counts the numbers of words in a string. It returns each word and the multiplicity}
14
14
  s.email = %q{ivan@bakedweb.net}
15
15
  s.extra_rdoc_files = [
@@ -1,32 +1,44 @@
1
- class Contador
1
+ class Contador
2
2
 
3
3
  attr_accessor :string
4
4
 
5
- def initialize(string)
5
+ def initialize(string)
6
+ @omit = []
6
7
  @string = string
7
8
  @final = Hash.new
8
9
  split_string_into_hash
10
+ delete_omits if $omits
9
11
  end
10
12
 
11
- def multiplicity
13
+ def delete_omits
14
+ $omits.split(' ').each do |word|
15
+ @final.delete(word.to_sym)
16
+ end
17
+ end
18
+
19
+ def multiplicity
12
20
  @final
13
21
  end
14
22
 
23
+ def omit(word)
24
+ @final.delete(word.to_sym)
25
+ end
26
+
15
27
  private
16
28
 
17
- def split_string_into_hash
29
+ def split_string_into_hash
18
30
  string.split(' ').each do |word|
19
31
  begin
20
- word.gsub!(/\W+/, '')
32
+ word.gsub!(/\W+/, '')
21
33
  key = word.downcase.to_sym
22
34
  if @final.has_key?(key)
23
- @final[key] += 1
35
+ @final[key] += 1
24
36
  else
25
37
  @final[key] = 1
26
38
  end
27
39
  rescue
28
40
  puts "Upsss.. #{word}"
29
41
  end
30
- end
42
+ end
31
43
  end
32
44
  end
@@ -1,5 +1,6 @@
1
+ require 'rubygems'
1
2
  require 'spec'
2
- require 'contador'
3
+ require 'lib/contador'
3
4
 
4
5
  describe Contador do
5
6
  it "returns an empty string for nothing " do
@@ -37,12 +38,24 @@ describe Contador do
37
38
  contador.multiplicity.should == {:esto => 2, :esta => 2, :depinga => 2}
38
39
  end
39
40
 
40
- it "handles long string cases" do
41
- string = "estan muyyy lindos cual es el precio por bolsito, estan cool Cuanto s su precio cual es su precio quisiera saber los precios ESTAN MUY LINDOS me encantan Donde estàn ubicados? hermosos por donde el envio y costo? - Quisiera saber el precio antes de comprar Quisiera saber el precio antes de comprar NO NINGUNO son bellos pero cuanto cuestan stan dmasiado beios me encantan estos bolso. en cuanto tiempo mas o menos tengo q hacerles el deposito? soy de maracaibo gracias cuanto es? umm okzz me gustaria saber si no hay otra rebaja por la cantidad?? y con posibilidades de comprar mas, gracias xD hola como estas quisiera que por fa me enciaras fotos de los bolsos y me dieras el precio especifica de c/u... y como hacemos con el envio?? :D - nop me gustan los bolsitos - nop noo q staan muuy lindos como es el envio"
41
+ end
42
42
 
43
- contador = Contador.new(string)
44
- contador.multiplicity.should == {:noo=>1, :precios=>1, :la=>1, :estos=>1, :cu=>1, :cuanto=>4, :gustaria=>1, :el=>8, :pero=>1, :enciaras=>1, :cual=>2, :soy=>1, :de=>6, :mas=>2, :ubicados=>1, :xd=>1, :y=>4, :bolsitos=>1, :beios=>1, :los=>3, :rebaja=>1, :especifica=>1, :bellos=>1, :o=>1, :cool=>1, :okzz=>1, :que=>1, :lindos=>3, :deposito=>1, :antes=>2, :tiempo=>1, :estàn=>1, :posibilidades=>1, :gustan=>1, :dmasiado=>1, :saber=>4, :muy=>1, :otra=>1, :dieras=>1, :son=>1, :bolsito=>1, :umm=>1, :estas=>1, :costo=>1, :muyyy=>1, :hacerles=>1, :muuy=>1, :fa=>1, :donde=>2, :con=>2, :en=>1, :nop=>2, :d=>1, :hay=>1, :stan=>1, :quisiera=>4, :bolsos=>1, :ninguno=>1, :por=>4, :gracias=>2, :como=>3, :no=>2, :envio=>3, :estan=>3, :tengo=>1, :staan=>1, :es=>4, :encantan=>2, :cantidad=>1, :q=>2, :bolso=>1, :hacemos=>1, :su=>2, :me=>6, :si=>1, :s=>1, :cuestan=>1, :fotos=>1, :precio=>6, :maracaibo=>1, :comprar=>3, :menos=>1, :hermosos=>1, :hola=>1}
43
+ describe Contador, "No sally words" do
44
+ it "omits some basic words" do
45
+ contador = Contador.new("y y y precio")
46
+ contador.omit("y")
47
+ contador.multiplicity.should == {:precio => 1}
48
+ end
45
49
 
50
+ it "knows about a constant and omits those words" do
51
+ $omits = "y"
52
+ contador = Contador.new("y y y wasa")
53
+ contador.multiplicity.should == {:wasa => 1}
46
54
  end
47
55
 
56
+ it "knows about a contant with multiple words" do
57
+ $omits = "y que yo"
58
+ contador = Contador.new("y que yo precio")
59
+ contador.multiplicity.should == {:precio => 1}
60
+ end
48
61
  end
metadata CHANGED
@@ -4,10 +4,10 @@ version: !ruby/object:Gem::Version
4
4
  hash: 23
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 2
9
9
  - 0
10
- version: 0.2.0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ivan Acosta-Rubio
@@ -15,14 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-20 00:00:00 -05:00
18
+ date: 2011-03-31 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- type: :development
24
- name: bundler
25
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ requirement: &id001 !ruby/object:Gem::Requirement
26
23
  none: false
27
24
  requirements:
28
25
  - - ~>
@@ -33,12 +30,12 @@ dependencies:
33
30
  - 0
34
31
  - 0
35
32
  version: 1.0.0
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
38
- prerelease: false
39
33
  type: :development
40
- name: jeweler
41
- version_requirements: &id002 !ruby/object:Gem::Requirement
34
+ name: bundler
35
+ prerelease: false
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
42
39
  none: false
43
40
  requirements:
44
41
  - - ~>
@@ -49,12 +46,12 @@ dependencies:
49
46
  - 5
50
47
  - 1
51
48
  version: 1.5.1
52
- requirement: *id002
53
- - !ruby/object:Gem::Dependency
54
- prerelease: false
55
49
  type: :development
56
- name: rspec
57
- version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ name: jeweler
51
+ prerelease: false
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ requirement: &id003 !ruby/object:Gem::Requirement
58
55
  none: false
59
56
  requirements:
60
57
  - - ">="
@@ -63,12 +60,12 @@ dependencies:
63
60
  segments:
64
61
  - 0
65
62
  version: "0"
66
- requirement: *id003
67
- - !ruby/object:Gem::Dependency
68
- prerelease: false
69
63
  type: :development
70
64
  name: rspec
71
- version_requirements: &id004 !ruby/object:Gem::Requirement
65
+ prerelease: false
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ requirement: &id004 !ruby/object:Gem::Requirement
72
69
  none: false
73
70
  requirements:
74
71
  - - ">"
@@ -79,7 +76,10 @@ dependencies:
79
76
  - 2
80
77
  - 3
81
78
  version: 1.2.3
82
- requirement: *id004
79
+ type: :development
80
+ name: rspec
81
+ prerelease: false
82
+ version_requirements: *id004
83
83
  description: This gem counts the numbers of words in a string. It returns each word and the multiplicity
84
84
  email: ivan@bakedweb.net
85
85
  executables: []