array_utility 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 66035a12a194d47cd799f876ff4570ed66949a95
4
+ data.tar.gz: b959f21f2dfb3fafe72c06a111c78ae5029ba8c5
5
+ SHA512:
6
+ metadata.gz: cf392b49fdfe79f83fa3797b36698ae2b22b720bd48ee860b1210254413e93c22f8954d155e2ab4591f12ae8137bd19c914aed6c40f696a4a5c54cf6df4c3bc7
7
+ data.tar.gz: 0e52a964c661d96ba4958dc79ffac520bbdcc8ea17ee7696be3e22f87ef5735e98aa5e064e3a941b30ad2a7762d8fb6443171d8dc8d852f903c2f8d922a31986
@@ -0,0 +1,19 @@
1
+ module ArrayUtility
2
+ refine Array do
3
+ # Gets the next value in the Array.
4
+ # @param single [Any] The starting value.
5
+ # @return [Any] The value directly after single.
6
+ # @return [Nil] If there is no value after single.
7
+ def next(single)
8
+ self[index(single) + 1]
9
+ end
10
+
11
+ # Gets the previous value in the Array. Unlike #next, this method will never
12
+ # return Nil. Instead it will simply loop back to the end of the Array.
13
+ # @param single [Any] The starting value.
14
+ # @return [Any] The value directly before single.
15
+ def before(single)
16
+ self[index(single) - 1]
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ require 'test/unit'
2
+ require_relative '../lib/array_utility'
3
+
4
+ class TestBefore < Test::Unit::TestCase
5
+ using ArrayUtility
6
+ def test_before
7
+ assert_equal(2, [1, 2, 3].before(3))
8
+ assert_equal(3, [1, 2, 3].before(1))
9
+ end
10
+ end
data/spec/test_next.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'test/unit'
2
+ require_relative '../lib/array_utility'
3
+
4
+ class TestNext < Test::Unit::TestCase
5
+ using ArrayUtility
6
+ def test_next
7
+ assert_equal(2, [1, 2, 3].next(1))
8
+ assert_equal(nil, [1, 2, 3].next(3))
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: array_utility
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eli Foster
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Some simple but very useful utilities for Array objects. It primarily
14
+ focuses on using the most efficient methods to get certain values from Arrays. Eventually
15
+ it may have methods for manipulating Arrays.
16
+ email: elifosterwy@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/array_utility.rb
22
+ - spec/test_before.rb
23
+ - spec/test_next.rb
24
+ homepage: https://github.com/elifoster/array_utility
25
+ licenses: []
26
+ metadata:
27
+ issue_tracker: https://github.com/elifoster/array_utility/issues
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '2.1'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.4.5.1
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Provides some simple utilities for Array objects.
48
+ test_files: []
49
+ has_rdoc: