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 +4 -4
- data/lib/shellopts/args.rb +29 -18
- data/lib/shellopts/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 188e8a420eb3e7ead116f7daffaff32761f12be4efa9d8aa583cfb8050ee4a8b
|
4
|
+
data.tar.gz: 474ae6c949005b53201a7d62a03b53d6f57b263746c2bfeac681a93fb05d880e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2734bcdec0f1d3b68a26675eee2dd172b776be45b333917e74f7935912410bbc620ab152610820392b73ffe061e8e38d8c6cb8698faf94387655337de4d38d26
|
7
|
+
data.tar.gz: 7dd0c8dea7d12c259212b72551a769a11cda450df81b17f370cbc242ef5fbee28f2b0ecc739e9b2d4307ee65505e3bc939ebe433797d52b708b30f20a287b454
|
data/lib/shellopts/args.rb
CHANGED
@@ -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
|
15
|
-
# the
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
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
|
-
|
44
|
+
range = count_or_range
|
45
|
+
range.cover?(self.size) or inoa(message)
|
36
46
|
self.shift(self.size)
|
37
47
|
else
|
38
|
-
|
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
|
data/lib/shellopts/version.rb
CHANGED