contador 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "bundler", "~> 1.0.0"
5
+ gem "jeweler", "~> 1.5.1"
6
+ gem "rspec"
7
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.1)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rspec (1.3.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.0.0)
17
+ jeweler (~> 1.5.1)
18
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Ivan Acosta-Rubio
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ TALLY
2
+ ====
3
+
4
+ It a way to count the amount of times each word appears on a string.
5
+
6
+ USAGE
7
+ -----
8
+
9
+ `@sentence = Tally.new("Tally is cool.")`
10
+
11
+ `=> #<Tally:0x10103f488 @final={:is=>1, :cool=>1, :tally=>1}, @string="Tally is cool.">`
12
+
13
+ `@sentence.multiplicity`
14
+
15
+ `=> {:is=>1, :cool=>1, :tally=>1}`
16
+
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = tally
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to tally
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Ivan Acosta-Rubio. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "contador"
16
+ gem.homepage = "http://github.com/ivanacostarubio/contador"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{This gem counts the numbers of words in a string. It returns each word and the multiplicity}
19
+ gem.description = %Q{This gem counts the numbers of words in a string. It returns each word and the multiplicity}
20
+ gem.email = "ivan@bakedweb.net"
21
+ gem.authors = ["Ivan Acosta-Rubio"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+
30
+ require 'rake/rdoctask'
31
+ Rake::RDocTask.new do |rdoc|
32
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
33
+
34
+ rdoc.rdoc_dir = 'rdoc'
35
+ rdoc.title = "tally #{version}"
36
+ rdoc.rdoc_files.include('README*')
37
+ rdoc.rdoc_files.include('lib/**/*.rb')
38
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/contador.gemspec ADDED
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{contador}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ivan Acosta-Rubio"]
12
+ s.date = %q{2010-11-20}
13
+ s.description = %q{This gem counts the numbers of words in a string. It returns each word and the multiplicity}
14
+ s.email = %q{ivan@bakedweb.net}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".DS_Store",
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "contador.gemspec",
31
+ "lib/.DS_Store",
32
+ "lib/tally.rb",
33
+ "spec/spec.opts",
34
+ "spec/tally_spec.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/ivanacostarubio/contador}
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.7}
40
+ s.summary = %q{This gem counts the numbers of words in a string. It returns each word and the multiplicity}
41
+ s.test_files = [
42
+ "spec/tally_spec.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
52
+ s.add_development_dependency(%q<rspec>, [">= 0"])
53
+ s.add_development_dependency(%q<rspec>, ["> 1.2.3"])
54
+ else
55
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
57
+ s.add_dependency(%q<rspec>, [">= 0"])
58
+ s.add_dependency(%q<rspec>, ["> 1.2.3"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
63
+ s.add_dependency(%q<rspec>, [">= 0"])
64
+ s.add_dependency(%q<rspec>, ["> 1.2.3"])
65
+ end
66
+ end
67
+
data/lib/.DS_Store ADDED
Binary file
data/lib/tally.rb ADDED
@@ -0,0 +1,32 @@
1
+ class Tally
2
+
3
+ attr_accessor :string
4
+
5
+ def initialize(string)
6
+ @string = string
7
+ @final = Hash.new
8
+ split_string_into_hash
9
+ end
10
+
11
+ def multiplicity
12
+ @final
13
+ end
14
+
15
+ private
16
+
17
+ def split_string_into_hash
18
+ string.split(' ').each do |word|
19
+ begin
20
+ word.gsub!(/\W+/, '')
21
+ key = word.downcase.to_sym
22
+ if @final.has_key?(key)
23
+ @final[key] += 1
24
+ else
25
+ @final[key] = 1
26
+ end
27
+ rescue
28
+ puts "Upsss.. #{word}"
29
+ end
30
+ end
31
+ end
32
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,48 @@
1
+ require 'spec'
2
+ require 'tally'
3
+
4
+ describe Tally do
5
+ it "returns an empty string for nothing " do
6
+ contador = Tally.new(" ")
7
+ contador.multiplicity.should == {}
8
+ end
9
+
10
+ it "handles a single word" do
11
+ contador = Tally.new("cuenta")
12
+ contador.multiplicity.should == {:cuenta => 1}
13
+ end
14
+
15
+ it "handles a couple of words" do
16
+ contador = Tally.new("estudio estudio")
17
+ contador.multiplicity.should == {:estudio => 2}
18
+ end
19
+
20
+ it "handles multiple single words" do
21
+ contador = Tally.new("estudio estudio estudio estudio estudio estudio")
22
+ contador.multiplicity.should == {:estudio => 6}
23
+ end
24
+
25
+ it "handles real sentences" do
26
+ contador = Tally.new("Cuando voy a estudiar me siento muy bien")
27
+ contador.multiplicity.should == {:cuando => 1, :voy => 1, :a => 1, :estudiar => 1, :me => 1, :siento => 1, :muy => 1, :bien => 1}
28
+ end
29
+
30
+ it "handles duplicates words in sentences" do
31
+ contador = Tally.new("Ruby es depinga. Muy depinga.")
32
+ contador.multiplicity.should == {:ruby => 1, :es => 1, :depinga => 2, :muy => 1}
33
+ end
34
+
35
+ it "handles weir case" do
36
+ contador = Tally.new("Esto esta depinga. Depinga esta esto.")
37
+ contador.multiplicity.should == {:esto => 2, :esta => 2, :depinga => 2}
38
+ end
39
+
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"
42
+
43
+ contador = Tally.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}
45
+
46
+ end
47
+
48
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contador
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Ivan Acosta-Rubio
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-20 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 23
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ version: 1.0.0
33
+ type: :development
34
+ name: bundler
35
+ prerelease: false
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 1
44
+ segments:
45
+ - 1
46
+ - 5
47
+ - 1
48
+ version: 1.5.1
49
+ type: :development
50
+ name: jeweler
51
+ prerelease: false
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ name: rspec
65
+ prerelease: false
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">"
72
+ - !ruby/object:Gem::Version
73
+ hash: 25
74
+ segments:
75
+ - 1
76
+ - 2
77
+ - 3
78
+ version: 1.2.3
79
+ type: :development
80
+ name: rspec
81
+ prerelease: false
82
+ version_requirements: *id004
83
+ description: This gem counts the numbers of words in a string. It returns each word and the multiplicity
84
+ email: ivan@bakedweb.net
85
+ executables: []
86
+
87
+ extensions: []
88
+
89
+ extra_rdoc_files:
90
+ - LICENSE.txt
91
+ - README.md
92
+ - README.rdoc
93
+ files:
94
+ - .DS_Store
95
+ - .document
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - LICENSE.txt
99
+ - README.md
100
+ - README.rdoc
101
+ - Rakefile
102
+ - VERSION
103
+ - contador.gemspec
104
+ - lib/.DS_Store
105
+ - lib/tally.rb
106
+ - spec/spec.opts
107
+ - spec/tally_spec.rb
108
+ has_rdoc: true
109
+ homepage: http://github.com/ivanacostarubio/contador
110
+ licenses:
111
+ - MIT
112
+ post_install_message:
113
+ rdoc_options: []
114
+
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ hash: 3
132
+ segments:
133
+ - 0
134
+ version: "0"
135
+ requirements: []
136
+
137
+ rubyforge_project:
138
+ rubygems_version: 1.3.7
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: This gem counts the numbers of words in a string. It returns each word and the multiplicity
142
+ test_files:
143
+ - spec/tally_spec.rb