roulette-wheel-selection 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b9666d28896171b78e19cf6b50a123b9177b5048695ac7d21b7ea7cfb8abf0b3
4
- data.tar.gz: 194ece6957aadd240d567272d3d81edb98cd88c1a7c4f4f7686759ce8eafddd4
3
+ metadata.gz: 7864a6072c1831b99454b876a1dbb252bce3d64ec8d8419270caee1bbb7d62ab
4
+ data.tar.gz: 3d043783e6a9a207bd3dd5536d80e47b8aec7c956e43187c320fc31d6543f794
5
5
  SHA512:
6
- metadata.gz: 74fd4bbcd66a24710c52b3fae66b8fcb7cf2af4b9da3b5ecd8615f0d4fbda6c5c2cc894bab9aadb00b5669d27318388ff6394961e6e0acd10682cf1831d1d31c
7
- data.tar.gz: a88b3ba11e7ab066e5e35fa57b0da7d3c90ced0b4375e00ac7281f30d7c61c97aa141f937d17c2a72d0e7bda5a081531e4dff808994a74071778586483776387
6
+ metadata.gz: 79f23433de5575f9e998cdf5d62f4527d5544cff5298b4be3795f3c84d480c984faea2b173d98d8ccb04aae1a3b55514c2a670fac00ca18043b2d6f5f9ef16df
7
+ data.tar.gz: 7f2782d3eec3ee671d5f8d8e27ac6cbb0889c1d7d0fe2cf8a3b893d49af760ae593f9d019386993c49b2c3a2cc7dd014720422f78a0397afde2896bed183daf0
@@ -1,6 +1,10 @@
1
1
  ## Change Log
2
2
 
3
- ### v1.0.1 2018/07/17
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 = 1)
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
@@ -1,3 +1,3 @@
1
1
  class RouletteWheelSelection
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
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.2
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-22 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler