shellopts 2.0.0.pre.3 → 2.0.0.pre.4

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: 34b7edfee1092f53f5c5c75d678c69b2fe753ecbcd6caa4876c923dd56dfbf68
4
- data.tar.gz: f7dfa30cd0ec280eb3f36e6a4779e01eeea1d14fd904fe2b42d1b7d7d9e40b63
3
+ metadata.gz: 188e8a420eb3e7ead116f7daffaff32761f12be4efa9d8aa583cfb8050ee4a8b
4
+ data.tar.gz: 474ae6c949005b53201a7d62a03b53d6f57b263746c2bfeac681a93fb05d880e
5
5
  SHA512:
6
- metadata.gz: e3d9b271783e3f9c5b42aa2511c36a78814f239e848829fd347ad74fc5289b769da7264defe8af985bce500485d7e9480a240b3f9e261d70943b1ebc69cd671d
7
- data.tar.gz: 3f91000787d5fa80570d378604a7cc28ef991585030bd1ce327b88e67dca3e4e647428d48863fc302165bcece5130cc2f140efb05fa478c2ff9443a7197a8b4e
6
+ metadata.gz: 2734bcdec0f1d3b68a26675eee2dd172b776be45b333917e74f7935912410bbc620ab152610820392b73ffe061e8e38d8c6cb8698faf94387655337de4d38d26
7
+ data.tar.gz: 7dd0c8dea7d12c259212b72551a769a11cda450df81b17f370cbc242ef5fbee28f2b0ecc739e9b2d4307ee65505e3bc939ebe433797d52b708b30f20a287b454
@@ -11,31 +11,42 @@ module ShellOpts
11
11
 
12
12
  # Remove and return elements from beginning of the array. If
13
13
  # +count_or_range+ is a number, that number of elements will be returned.
14
- # If the count is negative, the elements will be removed from the end of
15
- # the array. If +count_or_range+ is a range, the number of elements
16
- # returned will be in that range. The range can't contain negative numbers.
17
- # #expect calls #error() if there's is not enough elements in the array to
18
- # satisfy the request
19
- def extract(count, message = nil)
20
- self.size >= count.abs or inoa(message)
21
- start = count >= 0 ? 0 : size + count
22
- r = slice!(start, count.abs)
23
- r.size == 0 ? nil : (r.size == 1 ? r.first : r)
14
+ # If the count is one, a simple value is returned instead of an array. If
15
+ # the count is negative, the elements will be removed from the end of the
16
+ # array. If +count_or_range+ is a range, the number of elements returned
17
+ # will be in that range. The range can't contain negative numbers #expect
18
+ # calls #error() if there's is not enough elements in the array to satisfy
19
+ # the request
20
+ def extract(count_or_range, message = nil)
21
+ if count_or_range.is_a?(Range)
22
+ range = count_or_range
23
+ range.min <= self.size or inoa(message)
24
+ n_extract = [self.size, range.max].min
25
+ n_extend = range.max > self.size ? range.max - self.size : 0
26
+ r = self.shift(n_extract) + Array.new(n_extend)
27
+ else
28
+ count = count_or_range
29
+ self.size >= count.abs or inoa(message)
30
+ start = count >= 0 ? 0 : size + count
31
+ r = slice!(start, count.abs)
32
+ r.size == 0 ? nil : (r.size == 1 ? r.first : r)
33
+ end
24
34
  end
25
35
 
26
36
  # Remove and returns elements from the array. If +count_or_range+ is a
27
- # number, that number of elements will be returned. If the count is
28
- # negative, the elements will be removed from the end of the array. If
29
- # +count_or_range+ is a range, the number of elements returned will be in
30
- # that range. The range can't contain negative numbers. #expect calls
31
- # #error() if the array has remaning elemens after removal satisfy the
32
- # request
37
+ # number, that number of elements will be returned. If the count is one, a
38
+ # simple value is returned instead of an array. If +count_or_range+ is a
39
+ # range, the number of elements returned will be in that range. The range
40
+ # can't contain negative numbers. #expect calls #error() if the array has
41
+ # remaning elemens after removal satisfy the request
33
42
  def expect(count_or_range, message = nil)
34
43
  if count_or_range.is_a?(Range)
35
- count_or_range.cover?(self.size) or inoa(message)
44
+ range = count_or_range
45
+ range.cover?(self.size) or inoa(message)
36
46
  self.shift(self.size)
37
47
  else
38
- count_or_range == self.size or inoa(message)
48
+ count = count_or_range
49
+ count == self.size or inoa(message)
39
50
  r = self.shift(count)
40
51
  r.size == 0 ? nil : (r.size == 1 ? r.first : r)
41
52
  end
@@ -1,3 +1,3 @@
1
1
  module Shellopts
2
- VERSION = "2.0.0-3"
2
+ VERSION = "2.0.0-4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shellopts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.3
4
+ version: 2.0.0.pre.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen