randomer 0.0.4 → 0.0.5

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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZDE0MTc0MjQ1M2FkMjc5YTM3NmRmZjRmNjMyYmQ3YjNkNjY5ZWUzOA==
5
- data.tar.gz: !binary |-
6
- YjllMjBiMjc5MjljOTVmNTJhZGIxOWI3YzM3MTJmM2NiOGY4N2I1Mw==
2
+ SHA1:
3
+ metadata.gz: 00868cc02e109f937159b476b1b0c479db09e70b
4
+ data.tar.gz: 589bf1e71e20d227be6e7caf263da38fce8b8932
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- OWU0Y2FmMDgxNzRhYTJhYjI2YjkxYzBmYWQyOGFhNTU3YzE0NjRhOTAwN2Jm
10
- ZTM3OGRjNmY1MTliZWNiYWQ5ODg5Y2ExN2M2NjBkZTA5M2FiMTNlZDc1N2M5
11
- NDJlMDZkN2JkYTQ0NTYzYmY5OTM4NzM3MDk2NWE4OGU1ZTllMWE=
12
- data.tar.gz: !binary |-
13
- ZDFjYWVjMTdjYWI5MTdlMmFkYjY2MDE3ZjY3ZjNmOTEwNmJhZGQ3M2ExNzAy
14
- Y2IxMWZkZGM2NjJlNjMyZjY2NjViOTZiYjJiNWVkM2NhMDFmNmM3OTgyYjQw
15
- YmQ2NWZmMzNjNGNjMzAyNmI1OWNjYTQ2YmRjOWM3NTJhZDhjNzA=
6
+ metadata.gz: f64ae970d938c2a321b7f16d0a54e3d4c5c8b8a0b93c7568c05320cc6baa84f70e2c8546620232b83d2b95a92c2a59703b534b0e6a1e75c6dc9feaade1d06e09
7
+ data.tar.gz: c0cf46f785d1fb10f38c8dc6a05de12291de16af903e475ae396dd0153012c90bb1817c188dbfcc19b8f67de478fe9821bfd0ace716bcd7742169dd580fc4e24
data/.versions.conf CHANGED
@@ -1,2 +1,2 @@
1
- ruby=ruby-1.9.3
1
+ ruby=ruby-2.0.0
2
2
  ruby-gemset=randomer
@@ -1,3 +1,3 @@
1
1
  module Randomer
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/randomer.rb CHANGED
@@ -58,6 +58,7 @@ module Randomer
58
58
  end
59
59
 
60
60
  class Percent
61
+
61
62
  class << self
62
63
  ##
63
64
  # 根据一个hash中value指定的权重随机获取一个Symbol或String
@@ -91,6 +92,20 @@ module Randomer
91
92
  return keys[index] if range.include? rand_result
92
93
  end
93
94
  end
95
+
96
+ def pick_some(hash, count, mutex = true)
97
+ hash = hash.clone
98
+ _some = []
99
+ count.times do
100
+ key = self.pick_one hash
101
+ next if not key
102
+ _some << key
103
+ hash.delete key if mutex
104
+ end
105
+ _some
106
+ end
107
+
94
108
  end
109
+
95
110
  end
96
111
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Randomer::Percent do
4
+
4
5
  before(:each) do
5
6
  @percent_list = {
6
7
  :a => 900,
@@ -18,4 +19,12 @@ describe Randomer::Percent do
18
19
  (result == :e).should == false
19
20
  end
20
21
  end
22
+
23
+ it "Pick some from percent list" do
24
+ (0..10).each do |count|
25
+ Randomer::Percent.pick_some(@percent_list, count).count.should <= @percent_list.keys.count
26
+ Randomer::Percent.pick_some(@percent_list, count, false).count.should == count
27
+ end
28
+ end
29
+
21
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: randomer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zhuang Sirui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-23 00:00:00.000000000 Z
11
+ date: 2014-05-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A gem for random everything
14
14
  email:
@@ -39,17 +39,17 @@ require_paths:
39
39
  - lib
40
40
  required_ruby_version: !ruby/object:Gem::Requirement
41
41
  requirements:
42
- - - ! '>='
42
+ - - '>='
43
43
  - !ruby/object:Gem::Version
44
44
  version: '0'
45
45
  required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ! '>='
47
+ - - '>='
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  requirements: []
51
51
  rubyforge_project:
52
- rubygems_version: 2.1.10
52
+ rubygems_version: 2.2.2
53
53
  signing_key:
54
54
  specification_version: 4
55
55
  summary: Write a gem summary