darthjee-core_ext 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MATH_README.md +30 -0
- data/README.md +2 -0
- data/lib/darthjee/core_ext.rb +1 -0
- data/lib/darthjee/core_ext/math.rb +9 -0
- data/lib/darthjee/core_ext/version.rb +1 -1
- data/spec/lib/math_spec.rb +36 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2c5c7d0ee2381eb9ee8247dcf6958d094cc5048
|
4
|
+
data.tar.gz: c2edd6e256d0af3754a452dd1866ffab79e54c2b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a563d810e044f19c03347289e619c8ab3fae73572a475b14996009714ce136fcd50fd6586d814ef6b417d247f15d977be2b3c5d64545a2a15ec56548fd246fe9
|
7
|
+
data.tar.gz: 894aad77a3355ed2cd43104de005088acce770872bef017e0467363b4b66c9eb119bf2e5216661ae1ee911bb4f9e52fc4207d382a99573f4c971dbd6ba049d0b
|
data/MATH_README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
## MATH
|
2
|
+
|
3
|
+
### .average
|
4
|
+
calculates the average of the given values
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
Math.average([ 0, 1, 2, 3, 4 ])
|
8
|
+
```
|
9
|
+
|
10
|
+
returns
|
11
|
+
```
|
12
|
+
2
|
13
|
+
```
|
14
|
+
|
15
|
+
It can also be used to calculate the average of weighted values
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Math.average(
|
19
|
+
0 => 1,
|
20
|
+
1 => 2,
|
21
|
+
2 => 3,
|
22
|
+
3 => 4,
|
23
|
+
4 => 5
|
24
|
+
)
|
25
|
+
```
|
26
|
+
|
27
|
+
returns
|
28
|
+
```
|
29
|
+
2.6666
|
30
|
+
```
|
data/README.md
CHANGED
data/lib/darthjee/core_ext.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Math do
|
4
|
+
describe '.average' do
|
5
|
+
context 'when passing an array of values' do
|
6
|
+
let(:values) { [0, 1, 2, 3, 4] }
|
7
|
+
|
8
|
+
it 'returns the average' do
|
9
|
+
expect(described_class.average(values)).to eq(2)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when average is not a round number' do
|
13
|
+
let(:values) { [0, 1, 2, 3] }
|
14
|
+
it 'returns the average' do
|
15
|
+
expect(described_class.average(values)).to eq(1.5)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when passing a hash' do
|
21
|
+
let(:values) do
|
22
|
+
{
|
23
|
+
0 => 1,
|
24
|
+
1 => 2,
|
25
|
+
2 => 3,
|
26
|
+
3 => 4,
|
27
|
+
4 => 5
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'uses the keys as values and the values as weights (frequency)' do
|
32
|
+
expect(described_class.average(values)).to eq(8 / 3.0)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: darthjee-core_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darthjee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -137,6 +137,7 @@ files:
|
|
137
137
|
- Gemfile
|
138
138
|
- HASH_README.md
|
139
139
|
- LICENSE
|
140
|
+
- MATH_README.md
|
140
141
|
- OBJECT_README.md
|
141
142
|
- README.md
|
142
143
|
- Rakefile
|
@@ -154,6 +155,7 @@ files:
|
|
154
155
|
- lib/darthjee/core_ext/hash/deep_hash_constructor.rb
|
155
156
|
- lib/darthjee/core_ext/hash/key_changer.rb
|
156
157
|
- lib/darthjee/core_ext/hash/value_changer.rb
|
158
|
+
- lib/darthjee/core_ext/math.rb
|
157
159
|
- lib/darthjee/core_ext/numeric.rb
|
158
160
|
- lib/darthjee/core_ext/object.rb
|
159
161
|
- lib/darthjee/core_ext/object/default_value.rb
|
@@ -166,6 +168,7 @@ files:
|
|
166
168
|
- spec/lib/hash/deep_hash_constructor_spec.rb
|
167
169
|
- spec/lib/hash/key_changer_spec.rb
|
168
170
|
- spec/lib/hash_spec.rb
|
171
|
+
- spec/lib/math_spec.rb
|
169
172
|
- spec/lib/numeric_spec.rb
|
170
173
|
- spec/lib/object/default_value_spe.rb
|
171
174
|
- spec/lib/object_spec.rb
|
@@ -219,6 +222,7 @@ test_files:
|
|
219
222
|
- spec/lib/hash/deep_hash_constructor_spec.rb
|
220
223
|
- spec/lib/hash/key_changer_spec.rb
|
221
224
|
- spec/lib/hash_spec.rb
|
225
|
+
- spec/lib/math_spec.rb
|
222
226
|
- spec/lib/numeric_spec.rb
|
223
227
|
- spec/lib/object/default_value_spe.rb
|
224
228
|
- spec/lib/object_spec.rb
|