compter 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 39faaa85605f4a141dc065ddc99a73fa4ec54107
4
+ data.tar.gz: eaa2c68d1e008ec6f07ebc33e8fb3c79b9901e28
5
+ SHA512:
6
+ metadata.gz: a09f437ad87ceaf4fce361bcb360e559e2e392bbcb9d4f5f0ea1700f47c48af6d23a5ea10a33010e740c930c41ffd6610207cafea2ada9dcf2da32aba05a1375
7
+ data.tar.gz: 763281636380016faa8f33620977fcf53f642224d4567692d679442b9f916cf45e4afe52f3826602b766fc4e642c641c529705cd4fbee0e1f83a4f558940efa1
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "shoulda", ">= 0"
7
+ gem "rspec"
8
+ gem "rake"
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Pedro Vereza
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require "bundler/gem_tasks"
2
+ require 'bundler'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require "compter/version"
7
+
8
+ require 'rspec/core'
9
+ require 'rspec/core/rake_task'
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
11
+ spec.pattern = FileList['spec/**/*_spec.rb']
12
+ end
13
+
14
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
15
+ spec.pattern = 'spec/**/*_spec.rb'
16
+ spec.rcov_opts = %w{--exclude .bundler,.rvm}
17
+ spec.rcov = true
18
+ end
19
+
20
+ task :default => :spec
21
+
data/compter.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'compter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "compter"
8
+ spec.version = Compter::VERSION
9
+ spec.authors = ["Pedro Vereza"]
10
+ spec.email = ["pdrvereza@gmail.com"]
11
+ spec.description = "Count strings that match given expressions"
12
+ spec.summary = "Counter"
13
+ spec.license = "MIT"
14
+ spec.homepage = "https://github.com/pedrovereza/compter"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,20 @@
1
+ module Compter
2
+
3
+ class Counter
4
+ def count_occurrences_of(text, input)
5
+ input.scan(text).size
6
+ end
7
+
8
+ def count_per_identifiers(identifiers, input)
9
+ results = Hash.new
10
+
11
+ identifiers.each do |identifier, text|
12
+ results[identifier] = count_occurrences_of(text, input)
13
+
14
+ end
15
+
16
+ results
17
+ end
18
+ end
19
+ end
20
+
@@ -0,0 +1,3 @@
1
+ module Compter
2
+ VERSION = "0.0.1"
3
+ end
data/lib/compter.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "compter/version"
2
+
3
+ module Compter
4
+
5
+
6
+ def self.load
7
+ require "compter/counter"
8
+ end
9
+ end
10
+
11
+ Compter.load
@@ -0,0 +1,27 @@
1
+ require 'bundler/setup'
2
+ Bundler.require
3
+
4
+
5
+ describe "it counts occurrence of text in input" do
6
+
7
+ before(:each) do
8
+ @compter = Compter::Counter.new
9
+ end
10
+
11
+ it "it counts occurence of text in input" do
12
+ occurences = @compter.count_occurrences_of("abc", "123456 abc 7890")
13
+
14
+ occurences.should == 1
15
+ end
16
+
17
+ it "counts occurences per identifier" do
18
+ identifiers = {"letters" => "abc",
19
+ "one-to-six" => "123456",
20
+ "not-found" => "hue"
21
+ }
22
+
23
+ occurences_per_identifiers = @compter.count_per_identifiers(identifiers, "123456 abc 789")
24
+
25
+ occurences_per_identifiers.should == {"letters" => 1, "one-to-six" => 1, "not-found" => 0}
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Vereza
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Count strings that match given expressions
42
+ email:
43
+ - pdrvereza@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - Rakefile
52
+ - compter.gemspec
53
+ - lib/compter.rb
54
+ - lib/compter/counter.rb
55
+ - lib/compter/version.rb
56
+ - spec/compter_spec.rb
57
+ homepage: https://github.com/pedrovereza/compter
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.0.14
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Counter
81
+ test_files:
82
+ - spec/compter_spec.rb