array-subindex 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -5
- data/lib/array/subindex.rb +2 -2
- data/lib/array/subindex/version.rb +1 -1
- data/spec/lib/array/subindex_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5bd593c29d9bf506cfc8c8c4236c027f643788c
|
4
|
+
data.tar.gz: 3b500bdf72d283175ad127a0486c4a4d26266913
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a082683202f921635b63259829fcdc06bfd791bd36308954d1fb38da092c8abd4ee79382bd05a77650f44879c5f90e129cace7c1e148b95c5c56ab6c37eb6f42
|
7
|
+
data.tar.gz: cccdcaa249aea013da28564fbccedf398145fce90f735d5cbf2307acc08d4a39c552d5c5892c3aca94f71f3e61fbcbec77f5f5ff531fed0fa510bdadbee7948e
|
data/README.md
CHANGED
@@ -57,15 +57,14 @@ adjacent indexes, adds them, and returns them. For example:
|
|
57
57
|
It also works for unequal devisions (e.g. indexes other than 0.5):
|
58
58
|
|
59
59
|
```ruby
|
60
|
-
[1,2,3][0.25] == 1.
|
61
|
-
#
|
60
|
+
[1,2,3][0.25] == 1.25
|
61
|
+
# 3/4 of index 0 + 1/4 of index 1
|
62
62
|
```
|
63
63
|
|
64
64
|
In the case of irrational divisions, the results are rounded:
|
65
65
|
|
66
66
|
```ruby
|
67
|
-
[1,2,3][1.001] == 2.
|
68
|
-
but rounded to 2.999
|
67
|
+
[1,2,3][1.001] == 2.001
|
69
68
|
```
|
70
69
|
|
71
70
|
For arrays of strings, a concatination of portions of the values are used:
|
@@ -105,4 +104,7 @@ Distributed under the [WTFPL](https://github.com/rlespinasse/WTFPL) license.
|
|
105
104
|
|
106
105
|
## Contributing
|
107
106
|
|
108
|
-
1. Don't. Stop encouraging me to commit these kinds of sin.
|
107
|
+
1. Don't. Stop encouraging me to commit these kinds of sin.
|
108
|
+
|
109
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/xunker/array-subindex/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
110
|
+
|
data/lib/array/subindex.rb
CHANGED
@@ -26,8 +26,8 @@ class Array
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def subindex_as_number(subindex, f_value, c_value)
|
29
|
-
f_fractional = f_value.to_f * subindex
|
30
|
-
c_fractional = c_value.to_f *
|
29
|
+
f_fractional = f_value.to_f * (1.0 - subindex)
|
30
|
+
c_fractional = c_value.to_f * subindex
|
31
31
|
f_fractional + c_fractional
|
32
32
|
end
|
33
33
|
|
@@ -23,17 +23,17 @@ describe 'Array::subindex' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "will add parts unequally" do
|
26
|
-
#
|
26
|
+
# 3/4 of index 0 + 1/4 of index 1
|
27
27
|
expect(
|
28
28
|
subject[0.25]
|
29
|
-
).to eq( 0.
|
29
|
+
).to eq( 0.75 + 0.5)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "will round values" do
|
33
|
-
# expect 0.
|
33
|
+
# expect 0.998 of index 1 and 0.001 index 2, but rounded
|
34
34
|
expect(
|
35
35
|
subject[1.001]
|
36
|
-
).to eq( 2.
|
36
|
+
).to eq( 2.001)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "can accept Rational as index" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: array-subindex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Nielsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|