array-subindex 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/lib/array/subindex.rb +2 -2
- data/lib/array/subindex/version.rb +1 -1
- data/spec/lib/array/subindex_spec.rb +25 -1
- metadata +2 -4
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f5db374dd0ca57607077d4ad679fc1717ed5e5b
|
4
|
+
data.tar.gz: be07e6686cd7f1ba38ff7ae2045263609b6debfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1df0dbd96669327b1e64ac5e9e761f206876f073a8489aaf8215f6e8e4f71c3035e47dbf82a76608cacf96a40a1f9bcd26976a02795cca595b86260f34b3b6cc
|
7
|
+
data.tar.gz: 5190f223f418ea975a1b52ef3e7177980c00ca3964eb0d73bb6a6e97c8b486b885bee892f2fe9caca711985dcc3e79bd8e7bd21e675169c024ee0de66bf83ac5
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -35,7 +35,7 @@ require 'array/subindex'
|
|
35
35
|
|
36
36
|
## Usage
|
37
37
|
|
38
|
-
This gem overrides the Ruby core Array#[] method. That is
|
38
|
+
This gem overrides the Ruby core Array#[] method. That is insane. If a
|
39
39
|
"normal" integer is used, the method behaves as normal:
|
40
40
|
|
41
41
|
```ruby
|
data/lib/array/subindex.rb
CHANGED
@@ -35,9 +35,9 @@ private
|
|
35
35
|
f_value = f_value.to_s
|
36
36
|
c_value = c_value.to_s
|
37
37
|
f_index = (f_value.length * subindex).to_i
|
38
|
-
c_index = (c_value.length *
|
38
|
+
c_index = (c_value.length * subindex).to_i
|
39
39
|
[
|
40
|
-
f_value.slice(f_index, f_value.length
|
40
|
+
f_value.slice(f_index, f_value.length),
|
41
41
|
c_value.slice(0, c_index)
|
42
42
|
].join
|
43
43
|
end
|
@@ -35,6 +35,12 @@ describe 'Array::subindex' do
|
|
35
35
|
subject[1.001]
|
36
36
|
).to eq( 2.999)
|
37
37
|
end
|
38
|
+
|
39
|
+
it "can accept Rational as index" do
|
40
|
+
expect(
|
41
|
+
subject[Rational(3,2)]
|
42
|
+
).to eq( 1.0 + 1.5)
|
43
|
+
end
|
38
44
|
end
|
39
45
|
|
40
46
|
context "adjacent values are strings" do
|
@@ -51,7 +57,17 @@ describe 'Array::subindex' do
|
|
51
57
|
expect(
|
52
58
|
subject[0.25]
|
53
59
|
).to eq(
|
54
|
-
"
|
60
|
+
"his"
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "deals with uneven subindexes" do
|
65
|
+
strings = %w{ foo bar baz }
|
66
|
+
|
67
|
+
expect(
|
68
|
+
strings[1.3]
|
69
|
+
).to eq(
|
70
|
+
"bar"
|
55
71
|
)
|
56
72
|
end
|
57
73
|
|
@@ -64,6 +80,14 @@ describe 'Array::subindex' do
|
|
64
80
|
"oob"
|
65
81
|
)
|
66
82
|
end
|
83
|
+
|
84
|
+
it "can accept Rational as index" do
|
85
|
+
expect(
|
86
|
+
subject[Rational(1,2)]
|
87
|
+
).to eq(
|
88
|
+
"isi"
|
89
|
+
)
|
90
|
+
end
|
67
91
|
end
|
68
92
|
|
69
93
|
context "adjacent values are mix of string and numeric" 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.1.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-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,8 +60,6 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
|
-
- .ruby-gemset
|
64
|
-
- .ruby-version
|
65
63
|
- .travis.yml
|
66
64
|
- Gemfile
|
67
65
|
- LICENSE.txt
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
array-subindex
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.0.0
|