tarvit-helpers 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/tarvit-helpers/extensions/counter.rb +21 -0
- data/spec/extensions/counter_spec.rb +31 -0
- data/spec/spec_helper.rb +1 -0
- data/tarvit-helpers.gemspec +5 -3
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 644c35d394db579b8425b82ed1f9e29db00b0167
|
4
|
+
data.tar.gz: 61b3837f381c44253a35d0cccaa8e9fd28d3d874
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e63338bb91c26d064da40ad2aea2f5fb4a3b12a5cf36a5d609f25e2f70e852301cfdb0bf7d7b0eed546ab75a4ac1ad9d91c23c586fbfe34841d2fa8f8b42ad9
|
7
|
+
data.tar.gz: 60964357f695dfef8383b61c31303f2fd2b09da42bc38603156626ca470977024d8cd414a750f8961aabe4bcd59c23c4e155d436cdb0916eb5d102b07fad8c59
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.9
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Array
|
2
|
+
|
3
|
+
def info_by_rule(info, &rule)
|
4
|
+
counts = self.group_by{|x|
|
5
|
+
rule.(x)
|
6
|
+
}.to_a.map{|x|
|
7
|
+
x[1] = info.(x[1])
|
8
|
+
x
|
9
|
+
}
|
10
|
+
Hash[counts]
|
11
|
+
end
|
12
|
+
|
13
|
+
def count_by_rule(&rule)
|
14
|
+
info_by_rule(->(x){
|
15
|
+
x.count
|
16
|
+
}){|x|
|
17
|
+
rule.(x)
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NonSharedAccessors do
|
4
|
+
|
5
|
+
it 'should count by rule' do
|
6
|
+
|
7
|
+
array = [ '2', 2, 5, '8', 7, 3, 6, 1, 11 ]
|
8
|
+
|
9
|
+
expect(array.count_by_rule{|x| x.to_s == ?2 }).to eq({
|
10
|
+
true => 2,
|
11
|
+
false => 7
|
12
|
+
})
|
13
|
+
|
14
|
+
expect(array.count_by_rule{|x| x == 2 }).to eq({
|
15
|
+
true => 1,
|
16
|
+
false => 8
|
17
|
+
})
|
18
|
+
|
19
|
+
expect(array.count_by_rule{|x| x.to_i % 2 == 0 }).to eq({
|
20
|
+
true => 4,
|
21
|
+
false => 5
|
22
|
+
})
|
23
|
+
|
24
|
+
expect(array.count_by_rule{|x| x.to_s.include?(?1) }).to eq({
|
25
|
+
true => 2,
|
26
|
+
false => 7
|
27
|
+
})
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,6 +9,7 @@ require_relative '../lib/tarvit-helpers'
|
|
9
9
|
require_relative '../lib/tarvit-helpers/modules/non_shared_accessors'
|
10
10
|
require_relative '../lib/tarvit-helpers/modules/simple_crypt'
|
11
11
|
require_relative '../lib/tarvit-helpers/modules/conditional_logger'
|
12
|
+
require_relative '../lib/tarvit-helpers/extensions/counter'
|
12
13
|
|
13
14
|
include TarvitHelpers
|
14
15
|
|
data/tarvit-helpers.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: tarvit-helpers 0.0.
|
5
|
+
# stub: tarvit-helpers 0.0.9 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "tarvit-helpers"
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.9"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Vitaly Tarasenko"]
|
14
|
-
s.date = "2015-
|
14
|
+
s.date = "2015-07-05"
|
15
15
|
s.description = " Simple extensions to standard Ruby classes and useful helpers. "
|
16
16
|
s.email = "vetal.tarasenko@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -27,9 +27,11 @@ Gem::Specification.new do |s|
|
|
27
27
|
"VERSION",
|
28
28
|
"lib/tarvit-helpers.rb",
|
29
29
|
"lib/tarvit-helpers/extensions/colored_string.rb",
|
30
|
+
"lib/tarvit-helpers/extensions/counter.rb",
|
30
31
|
"lib/tarvit-helpers/modules/conditional_logger.rb",
|
31
32
|
"lib/tarvit-helpers/modules/non_shared_accessors.rb",
|
32
33
|
"lib/tarvit-helpers/modules/simple_crypt.rb",
|
34
|
+
"spec/extensions/counter_spec.rb",
|
33
35
|
"spec/modules/non_shared_accessors_spec.rb",
|
34
36
|
"spec/modules/simple_crypt_spec.rb",
|
35
37
|
"spec/spec_helper.rb",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tarvit-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vitaly Tarasenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -110,9 +110,11 @@ files:
|
|
110
110
|
- VERSION
|
111
111
|
- lib/tarvit-helpers.rb
|
112
112
|
- lib/tarvit-helpers/extensions/colored_string.rb
|
113
|
+
- lib/tarvit-helpers/extensions/counter.rb
|
113
114
|
- lib/tarvit-helpers/modules/conditional_logger.rb
|
114
115
|
- lib/tarvit-helpers/modules/non_shared_accessors.rb
|
115
116
|
- lib/tarvit-helpers/modules/simple_crypt.rb
|
117
|
+
- spec/extensions/counter_spec.rb
|
116
118
|
- spec/modules/non_shared_accessors_spec.rb
|
117
119
|
- spec/modules/simple_crypt_spec.rb
|
118
120
|
- spec/spec_helper.rb
|