pcbr 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pcbr.rb +17 -13
  3. data/spec/_spec.rb +25 -22
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b3ebecb25ead598113da23a081caff2edae89b2
4
- data.tar.gz: 017a54c57edab08278ea631356774a315a0ef976
3
+ metadata.gz: 2871f614f5c3e9fdf49297ebca1fc97e148eb3e3
4
+ data.tar.gz: 162ccfbbcaebf10c1e3a762f68ffcbc0b326888d
5
5
  SHA512:
6
- metadata.gz: 9935c310af1592e636e9e3c38bc239d7323053eb5c32e3c501ce974ecc17aab10d081892f988c0074b5e579fe8d19350d36d0bcaadceb10dc536a49e293dd58f
7
- data.tar.gz: 00ca5fcb6c35b5dec763a96638a25c3b39e548bad1e66f9c8b63905376d1470dc53ae5db0e2537c5a0229b88d30e44eff70bd75fe1624f9c62f32a1e7757439e
6
+ metadata.gz: 2f24b3e3e90bbde660ecd8c810e17f31cc949eefdb12b9d2b4a88746b9916023f16b6e379bc4f9fe9e7206b6741cdc4d489b07b6d768bb2ad7303973004867c7
7
+ data.tar.gz: 1702bac320df836e08bb1fef10195fa00b97ccd01a15b795cd8e082f6005c1c8f04233c9891eab78e4b392937fce1c4c73542de90e5f5812b9b4650899080d60
@@ -1,38 +1,42 @@
1
1
  class PCBR
2
2
 
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
 
5
5
  attr_reader :table
6
6
 
7
+ ARRAY_101 = [0, 0, 0]
7
8
  def initialize &block
8
9
  @table = []
9
- @callback = block || ->*_{[*_[0]]}
10
+ @callback = block || ( lambda do |a_, b_|
11
+ array = ARRAY_101.dup
12
+ [*a_].zip([*b_]) do |a, b|
13
+ next unless t = a <=> b
14
+ array[t] = t
15
+ end
16
+ array.inject :+
17
+ end )
10
18
  end
11
19
 
12
20
  # def size
13
21
  # @table.size
14
22
  # end
15
23
 
16
- ARRAY_101 = [0, 0, 0]
17
24
  def store key, *vector
18
- vector = vector.empty? ? [key] : vector.first
19
- calculated = @callback[vector, key]
25
+ vector = vector.empty? ? key : vector.first
20
26
  score = 0
21
27
  @table.each do |item|
22
- array = ARRAY_101.dup
23
- calculated.zip(item[3]).each do |a, b|
24
- next unless t = a <=> b
25
- array[t] = t
26
- end
27
- point = array.inject :+
28
+ fail unless [*vector].size == [*item[1]].size
29
+
30
+ point = @callback.call vector, item[1]
31
+
28
32
  score += point
29
33
  item[2] -= point
30
34
  end
31
- @table.push [key, vector, score, calculated]
35
+ @table.push [key, vector, score]
32
36
  end
33
37
 
34
38
  def score key
35
- @table.assoc(key)[-2]
39
+ @table.assoc(key)[2]
36
40
  end
37
41
 
38
42
  def sorted
@@ -31,26 +31,27 @@ describe "basic specs" do
31
31
 
32
32
  example "&block" do
33
33
  n = 0
34
- rating = PCBR.new do |item|
34
+ rating = PCBR.new do |a, b|
35
35
  n += 1
36
- [item[:goodness], -item[:badness]]
36
+ a <=> b
37
37
  end
38
- rating.store 3, {goodness: 0, badness: 2}
39
- rating.store 2, {goodness: 1, badness: 2}
40
- rating.store 1, {goodness: 1, badness: 1}
41
- expect(rating.sorted).to eq([1, 2, 3])
42
- expect(n).to eq(3)
38
+ rating.store 1
39
+ rating.store 2
40
+ rating.store 3
41
+ rating.store 4
42
+ expect(rating.sorted).to eq([4, 3, 2, 1])
43
+ expect(n).to eq(6)
43
44
  end
44
45
 
45
46
  example "#sorted and #score[key]" do
46
47
  rating = PCBR.new
47
48
  table = [
48
- [1, [1, 1], -1, [1, 1]],
49
- [2, [2, 2], 5, [2, 2]],
50
- [3, [0, 0], -5, [0, 0]],
51
- [4, [1, 2], 3, [1, 2]],
52
- [6, [1, 1], -1, [1, 1]],
53
- [5, [0, 2], -1, [0, 2]],
49
+ [1, [1, 1], -1],
50
+ [2, [2, 2], 5],
51
+ [3, [0, 0], -5],
52
+ [4, [1, 2], 3],
53
+ [6, [1, 1], -1],
54
+ [5, [0, 2], -1],
54
55
  ].each do |key, vector, |
55
56
  rating.store key, vector
56
57
  end
@@ -96,26 +97,28 @@ describe "examples" do
96
97
  "DOT: capistrano/capistrano" => {issue: 38, pr: 6, watch: 339, star: 8392, fork: 1365},
97
98
  }
98
99
 
99
- push_repos = lambda do |rating|
100
- repos.each do |repo_name, repo_stats|
101
- rating.store repo_name, repo_stats
100
+ create_rating = lambda do |&callback|
101
+ PCBR.new.tap do |rating|
102
+ repos.each do |repo_name, repo_stats|
103
+ rating.store repo_name, callback[repo_stats, repo_name]
104
+ end
102
105
  end
103
106
  end
104
107
 
105
- contribution_intensivity_rating = PCBR.new do |repo_stats| [
108
+ contribution_intensivity_rating = create_rating.call do |repo_stats| [
106
109
  repo_stats[:pr],
107
110
  -repo_stats[:fork],
108
- ] end.tap &push_repos
111
+ ] end
109
112
 
110
- quality_rating = PCBR.new do |repo_stats| [
113
+ quality_rating = create_rating.call do |repo_stats| [
111
114
  repo_stats[:star],
112
115
  -repo_stats[:issue],
113
- ] end.tap &push_repos
116
+ ] end
114
117
 
115
- resulting_rating = PCBR.new do |_, repo_name| [
118
+ resulting_rating = create_rating.call do |repo_stats, repo_name| [
116
119
  contribution_intensivity_rating.score(repo_name),
117
120
  quality_rating.score(repo_name),
118
- ] end.tap &push_repos
121
+ ] end
119
122
 
120
123
  aggregate_failures do
121
124
  expect(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pcbr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-07 00:00:00.000000000 Z
11
+ date: 2017-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler