pickup 0.0.10 → 0.0.11

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
  SHA1:
3
- metadata.gz: e2e6ae63af48eb1ff181735d1d88db79470e7b8d
4
- data.tar.gz: aab0f2462466c3149d0820a4a70f198d94daa489
3
+ metadata.gz: 1533293d956a1a06ceccf39a693f5718f1a2ead1
4
+ data.tar.gz: bbc60771078bea080db4eab391d6a448d927a8de
5
5
  SHA512:
6
- metadata.gz: 3a0cd64924a3b175b456cd5421f5da3112a8a8d1802c8f678809e399c832c3fcd5cc4c58641ce6562e58edd70bd88e0e9c1792a15a3c747410335d4e7abe3d15
7
- data.tar.gz: bd3adec20e7b61d7f14e8d0cb2d4f36ba8744f3b78cd20142158a2fe4523ba63fbf032f7cd8ae9955ae36059fa725d644f7a1fbe9d4208dc5e4845b26a5d2851
6
+ metadata.gz: 38b74b2aae9cfb9ad5bd606a2332364786b74954f6718a94c6a2eed2ab263a83abff0f3ee2e944a06fb04a3dd064d6e0f9c99f06ce44c0f629185a818e541c0c
7
+ data.tar.gz: 24789240487187618292db31609d935124523c5014fb568181782c0e8df45d87ec41a42964af3cfaab4e36b6ee846dd5f14fa41bb4dfa3f73f3d6a406e6e697d
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pickup
2
2
 
3
- Pickup helps you to pick item from collection by it's weight/probability
3
+ Pickup helps you to pick an item from a collection by its weight or probability.
4
4
 
5
5
  ## Installation
6
6
 
@@ -136,4 +136,4 @@ pickup.pick(1, key_func: name_func)
136
136
  2. Create your feature branch (`git checkout -b my-new-feature`)
137
137
  3. Commit your changes (`git commit -am 'Added some feature'`)
138
138
  4. Push to the branch (`git push origin my-new-feature`)
139
- 5. Create new Pull Request
139
+ 5. Create new Pull Request
@@ -117,6 +117,7 @@ class Pickup
117
117
  def random(count)
118
118
  raise "List is shorter then count of items you want to get" if uniq && list.size < count
119
119
  nums = count.times.map{ rand(max) }.sort
120
+ return [] if max == 0
120
121
  get_random_items(nums)
121
122
  end
122
123
 
@@ -1,3 +1,3 @@
1
1
  class Pickup
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -4,6 +4,7 @@ require 'ostruct'
4
4
  require 'stringio'
5
5
 
6
6
  describe Pickup do
7
+
7
8
  before do
8
9
  @list = {
9
10
  "selmon" => 1, # 1
@@ -49,7 +50,7 @@ describe Pickup do
49
50
  # Inspect the fake IO object for the deprecated warning.
50
51
  $stderr.rewind
51
52
  $stderr.string.chomp.must_equal("[DEPRECATED] Passing uniq as a boolean to MappedList's initialize method is deprecated. Please use the opts hash instead.")
52
-
53
+
53
54
  # Restore the original stderr.
54
55
  $stderr = orig_stderr
55
56
  end
@@ -116,4 +117,11 @@ describe Pickup do
116
117
  it "should take 5 fish (using custom weight function)" do
117
118
  @pickup3.pick(5, key_func: @key_func, weight_func: @weight_func).size.must_equal 5
118
119
  end
120
+
121
+ let(:list) { { "foo" => 0 } }
122
+ let(:pickup) { Pickup.new(list) }
123
+
124
+ it "should not devide by zero" do
125
+ pickup.pick(1)
126
+ end
119
127
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pickup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - fl00r
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-26 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Pickup helps you to pick item from collection by it's weight/probability
14
14
  email:
@@ -17,7 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - .gitignore
20
+ - ".gitignore"
21
21
  - Gemfile
22
22
  - LICENSE
23
23
  - README.md
@@ -37,17 +37,17 @@ require_paths:
37
37
  - lib
38
38
  required_ruby_version: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - '>='
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
42
  version: '1.9'
43
43
  required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  requirements: []
49
49
  rubyforge_project:
50
- rubygems_version: 2.0.6
50
+ rubygems_version: 2.2.2
51
51
  signing_key:
52
52
  specification_version: 4
53
53
  summary: Pickup helps you to pick item from collection by it's weight/probability