bootstripe 0.2.20 → 0.2.22
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 +7 -0
- data/.gitignore +1 -0
- data/lib/bootstripe/array_additions.rb +7 -1
- data/lib/bootstripe/hash_additions.rb +2 -2
- data/lib/bootstripe/version.rb +1 -1
- data/spec/array_additions_spec.rb +6 -1
- data/spec/frequency_spec.rb +10 -2
- metadata +10 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b91a5b12643e253c9c9be08748e90636c0148e31
|
4
|
+
data.tar.gz: 5dfb979d158fbb910a3726177b7a8bf42f847c52
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ef1c7c4edc8b067de27e9082df9627753f4e41f8456f45490f85c3b6477d300ecfd6cd4fa4c4069c3f3a3963a4fcf2b5745f04d6b1ad1a3ff1998fc7eb282ad9
|
7
|
+
data.tar.gz: 563487893fb0bb3e7b8a238b0810ca386396ca99e6fcc4911a8190f93bcca49dfd3afa75a0128f360395da9f9dbf262d468c7989bbcdbbd988a904c958f1966f
|
data/.gitignore
CHANGED
@@ -11,6 +11,12 @@ class Array
|
|
11
11
|
sum / size
|
12
12
|
end
|
13
13
|
|
14
|
+
def median
|
15
|
+
sorted = self.sort
|
16
|
+
len = sorted.length
|
17
|
+
return (sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0
|
18
|
+
end
|
19
|
+
|
14
20
|
def compakt
|
15
21
|
self.reject do |i|
|
16
22
|
i.nil? ||
|
@@ -47,4 +53,4 @@ class Array
|
|
47
53
|
sects
|
48
54
|
end
|
49
55
|
|
50
|
-
end
|
56
|
+
end
|
@@ -27,7 +27,7 @@ class Hash
|
|
27
27
|
def random_by_frequency(seed = nil)
|
28
28
|
options = select{ |k,v| v.is_a?(Fixnum) || (v.is_a?(Hash) && (v['frequency'] || v[:frequency])) }
|
29
29
|
total_frequency = options.map{ |k,v| v.is_a?(Hash) ? v['frequency'] || v[:frequency] : v }.sum
|
30
|
-
seed ||= rand
|
30
|
+
seed ||= (rand * total_frequency)
|
31
31
|
|
32
32
|
s = 0
|
33
33
|
options.find do |option, val|
|
@@ -38,4 +38,4 @@ class Hash
|
|
38
38
|
nil
|
39
39
|
end
|
40
40
|
|
41
|
-
end
|
41
|
+
end
|
data/lib/bootstripe/version.rb
CHANGED
data/spec/frequency_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe :frequency do
|
|
9
9
|
{ :name => 'three', :frequency => 1 }
|
10
10
|
]
|
11
11
|
|
12
|
-
options.random_by_frequency(5).should == options[0]
|
12
|
+
options.random_by_frequency(5.7).should == options[0]
|
13
13
|
options.random_by_frequency(12).should == options[1]
|
14
14
|
options.random_by_frequency(15).should == options[2]
|
15
15
|
end
|
@@ -38,4 +38,12 @@ describe :frequency do
|
|
38
38
|
options.random_by_frequency(15).should == 'three'
|
39
39
|
end
|
40
40
|
|
41
|
-
|
41
|
+
it 'should be pretty close to probability' do
|
42
|
+
options = {
|
43
|
+
'one' => 1,
|
44
|
+
'two' => 3
|
45
|
+
}
|
46
|
+
10000.times.count{ options.random_by_frequency == "two" }.should > 6000
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
metadata
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootstripe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.22
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Mike Laurence
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-03-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
description: A handful of useful additions for Ruby
|
@@ -34,7 +31,7 @@ executables: []
|
|
34
31
|
extensions: []
|
35
32
|
extra_rdoc_files: []
|
36
33
|
files:
|
37
|
-
- .gitignore
|
34
|
+
- ".gitignore"
|
38
35
|
- Gemfile
|
39
36
|
- Rakefile
|
40
37
|
- bootstripe.gemspec
|
@@ -58,27 +55,26 @@ files:
|
|
58
55
|
- spec/string_additions_spec.rb
|
59
56
|
homepage: http://bytebin.com
|
60
57
|
licenses: []
|
58
|
+
metadata: {}
|
61
59
|
post_install_message:
|
62
60
|
rdoc_options: []
|
63
61
|
require_paths:
|
64
62
|
- lib
|
65
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
64
|
requirements:
|
68
|
-
- -
|
65
|
+
- - ">="
|
69
66
|
- !ruby/object:Gem::Version
|
70
67
|
version: '0'
|
71
68
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
69
|
requirements:
|
74
|
-
- -
|
70
|
+
- - ">="
|
75
71
|
- !ruby/object:Gem::Version
|
76
72
|
version: '0'
|
77
73
|
requirements: []
|
78
74
|
rubyforge_project: bootstripe
|
79
|
-
rubygems_version:
|
75
|
+
rubygems_version: 2.2.2
|
80
76
|
signing_key:
|
81
|
-
specification_version:
|
77
|
+
specification_version: 4
|
82
78
|
summary: A handful of useful additions for Ruby
|
83
79
|
test_files:
|
84
80
|
- spec/array_additions_spec.rb
|