circular_array 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1502f1b9467ffb2d1b84ee196e1f3eaec0b4abad37fcd6cd6ed426be8b3b12e
4
- data.tar.gz: 22fe58e109230b2dfff133e894c00cddcec58d51afb3b5195ace726dafb8a9cb
3
+ metadata.gz: 89e06c14c6a321cdbed279de04d4bccdd018f5a16ec804b5b8253db4584f2117
4
+ data.tar.gz: 05b01f1c0c0e79c77e04f76770d927050ff7a7a7f64329885757262ba91b2503
5
5
  SHA512:
6
- metadata.gz: 1eae2753fe31859a4a81dbba9f7e130f69cb0fd58ac1555a40ed8afbbe35eb27fc4ea4a4f068bd625f54baabd0ed36643658aaad48fb7f56e3715aa4b5025a0c
7
- data.tar.gz: cbedcce0a227186cc897998a2640d93c605255194763da6ba126ac588ef500de38eca26ed0383fcffc6c0af914b2624b21093bf517a26f2918348d698f4dc57f
6
+ metadata.gz: b586230519054f33154e22b933b6c03cc1a81717d815869b8a6fd917c0c04da2b7efd1ccfcb3ffa28b2216af572ed88bc47e1859db6b673d0cc2d6f15cb3dd2d
7
+ data.tar.gz: b1dfd513506b1546291a4634d2fc539bb069dd9445e7efdcf30b5d629caada23a0280dee19ed36b450c2ec7a56d6c5c32cec8b15122cfbfdc00bdd50c945361f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- circular_array (0.1.0)
4
+ circular_array (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # CircularArray
2
2
 
3
- You have a week with days and you want to iterate over the week and never meet `nil`, but:
3
+ [![Build Status](https://travis-ci.com/sveredyuk/ruby-circular-array.svg?branch=master)](https://travis-ci.com/sveredyuk/ruby-circular-array)
4
+
5
+ You have a week with days and you want to iterate over the week and never met `nil`, but:
4
6
  ```ruby
5
7
  week = [:mon, :tue, :wed, :thu, :fri, :sat, :sun]
6
8
  week[0] # => :mon
7
9
  week[3] # => :thu
8
10
  week[6] # => :sun
9
- week[7] # => nil... stop waaat? I need monday!
11
+ week[7] # => nil... stop what?! I need monday!
10
12
  ```
11
13
 
12
14
  But it's possible with `CircularArray`
@@ -33,7 +35,7 @@ circular_week[14] # => :mon
33
35
  # great!
34
36
  ```
35
37
 
36
- **You can use it for recursion matching, but do not forget to add anti-infinity loop clause**
38
+ **You can use it for recursive matching, but do not forget to add anti-infinity loop clause**
37
39
 
38
40
  Only for empty collection in returns `nil`
39
41
  ```ruby
@@ -45,7 +47,7 @@ empty_circular_array[1] # => nil
45
47
 
46
48
  1. Matching over a list of possible solutions
47
49
  2. Cycling dates for complex delivery logic
48
- 3.
50
+ 3. ...
49
51
 
50
52
 
51
53
  ## Installation
@@ -1,14 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class CircularArray < Array
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
 
6
6
  def [](index)
7
- result = super
7
+ return nil if empty?
8
8
 
9
- return result if result
10
- return nil if size.zero?
11
-
12
- self[index - size]
9
+ super(index % size)
13
10
  end
14
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circular_array
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Volodya Sveredyuk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-05 00:00:00.000000000 Z
11
+ date: 2019-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler