roulette-wheel-selection 1.0.2 → 1.1.0
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 +4 -4
- data/CHANGELOG.md +5 -1
- data/lib/roulette-wheel-selection.rb +7 -2
- data/lib/roulette-wheel-selection/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7864a6072c1831b99454b876a1dbb252bce3d64ec8d8419270caee1bbb7d62ab
|
|
4
|
+
data.tar.gz: 3d043783e6a9a207bd3dd5536d80e47b8aec7c956e43187c320fc31d6543f794
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 79f23433de5575f9e998cdf5d62f4527d5544cff5298b4be3795f3c84d480c984faea2b173d98d8ccb04aae1a3b55514c2a670fac00ca18043b2d6f5f9ef16df
|
|
7
|
+
data.tar.gz: 7f2782d3eec3ee671d5f8d8e27ac6cbb0889c1d7d0fe2cf8a3b893d49af760ae593f9d019386993c49b2c3a2cc7dd014720422f78a0397afde2896bed183daf0
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
## Change Log
|
|
2
2
|
|
|
3
|
-
### v1.0.1
|
|
3
|
+
### [v1.0.2](https://github.com/khiav223577/roulette-wheel-selection/compare/v1.0.1...v1.0.2) 2019/01/22
|
|
4
|
+
- [#5](https://github.com/khiav223577/roulette-wheel-selection/pull/5) Support sampling N elements (@khiav223577)
|
|
5
|
+
- [#4](https://github.com/khiav223577/roulette-wheel-selection/pull/4) Fix: broken test cases after bundler 2.0 was released (@khiav223577)
|
|
6
|
+
|
|
7
|
+
### [v1.0.1](https://github.com/khiav223577/roulette-wheel-selection/compare/v1.0.0...v1.0.1) 2018/07/17
|
|
4
8
|
- [#3](https://github.com/khiav223577/roulette-wheel-selection/pull/3) Fix: zero weight objects should be ignored (@khiav223577)
|
|
5
9
|
- [#2](https://github.com/khiav223577/roulette-wheel-selection/pull/2) Fix: should return nil if input is empty (@khiav223577)
|
|
6
10
|
- [#1](https://github.com/khiav223577/roulette-wheel-selection/pull/1) try using new test reporter (@khiav223577)
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "roulette-wheel-selection/version"
|
|
2
4
|
|
|
3
5
|
class RouletteWheelSelection
|
|
6
|
+
NOT_SET = Object.new
|
|
7
|
+
|
|
4
8
|
class << self
|
|
5
9
|
def sample(*args)
|
|
6
10
|
object = args.first
|
|
@@ -28,11 +32,12 @@ class RouletteWheelSelection
|
|
|
28
32
|
@total_rate = hash.values.inject(&:+) || 0
|
|
29
33
|
end
|
|
30
34
|
|
|
31
|
-
def sample(num =
|
|
35
|
+
def sample(num = NOT_SET)
|
|
32
36
|
return if @total_rate == 0
|
|
37
|
+
return sample_an_object(@total_rate, @hash) if num == NOT_SET
|
|
33
38
|
return if num < 1
|
|
34
39
|
return sample_n_objects(num) if num > 1
|
|
35
|
-
return sample_an_object(@total_rate, @hash)
|
|
40
|
+
return [sample_an_object(@total_rate, @hash)]
|
|
36
41
|
end
|
|
37
42
|
|
|
38
43
|
private
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: roulette-wheel-selection
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- khiav reoy
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-01-
|
|
11
|
+
date: 2019-01-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|