shellopts 2.0.0.pre.2 → 2.0.0.pre.3
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 +28 -15
- data/lib/shellopts/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34b7edfee1092f53f5c5c75d678c69b2fe753ecbcd6caa4876c923dd56dfbf68
|
4
|
+
data.tar.gz: f7dfa30cd0ec280eb3f36e6a4779e01eeea1d14fd904fe2b42d1b7d7d9e40b63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3d9b271783e3f9c5b42aa2511c36a78814f239e848829fd347ad74fc5289b769da7264defe8af985bce500485d7e9480a240b3f9e261d70943b1ebc69cd671d
|
7
|
+
data.tar.gz: 3f91000787d5fa80570d378604a7cc28ef991585030bd1ce327b88e67dca3e4e647428d48863fc302165bcece5130cc2f140efb05fa478c2ff9443a7197a8b4e
|
data/lib/shellopts/args.rb
CHANGED
@@ -1,31 +1,44 @@
|
|
1
1
|
|
2
2
|
module ShellOpts
|
3
|
+
# Specialization of Array for arguments lists. Args extends Array with a
|
4
|
+
# #extract and an #expect method to extract elements from the array. The
|
5
|
+
# methods call #error() in response to errors
|
3
6
|
class Args < Array
|
4
7
|
def initialize(shellopts, *args)
|
5
8
|
@shellopts = shellopts
|
6
9
|
super(*args)
|
7
10
|
end
|
8
11
|
|
9
|
-
# Remove and return
|
10
|
-
#
|
11
|
-
#
|
12
|
+
# Remove and return elements from beginning of the array. If
|
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
|
12
19
|
def extract(count, message = nil)
|
13
20
|
self.size >= count.abs or inoa(message)
|
14
21
|
start = count >= 0 ? 0 : size + count
|
15
|
-
slice!(start, count.abs)
|
22
|
+
r = slice!(start, count.abs)
|
23
|
+
r.size == 0 ? nil : (r.size == 1 ? r.first : r)
|
16
24
|
end
|
17
25
|
|
18
|
-
#
|
19
|
-
#
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
# 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
|
33
|
+
def expect(count_or_range, message = nil)
|
34
|
+
if count_or_range.is_a?(Range)
|
35
|
+
count_or_range.cover?(self.size) or inoa(message)
|
36
|
+
self.shift(self.size)
|
37
|
+
else
|
38
|
+
count_or_range == self.size or inoa(message)
|
39
|
+
r = self.shift(count)
|
40
|
+
r.size == 0 ? nil : (r.size == 1 ? r.first : r)
|
41
|
+
end
|
29
42
|
end
|
30
43
|
|
31
44
|
private
|
data/lib/shellopts/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shellopts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.pre.
|
4
|
+
version: 2.0.0.pre.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Claus Rasmussen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|