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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79a36712cf9c41a500726cd042d9932f1c6ed7f7e7a334d5d245e0ad31185c75
4
- data.tar.gz: ddeec0f65a4d8e4250cbc9d1332626395c135d0c4e34d879fafcfb89b492699a
3
+ metadata.gz: 34b7edfee1092f53f5c5c75d678c69b2fe753ecbcd6caa4876c923dd56dfbf68
4
+ data.tar.gz: f7dfa30cd0ec280eb3f36e6a4779e01eeea1d14fd904fe2b42d1b7d7d9e40b63
5
5
  SHA512:
6
- metadata.gz: 2890ba5f277385eb8cc30a9e168d618f3633278cc41066c302ed82d7be46eeefb5a30f41a2471947bc78a0e55e8219cc472887a91b9d753a6687dfda605231e6
7
- data.tar.gz: a02ecb6e6613163f2915125ea0cd71cab30c7fd3c11f840a99bad0cb27b6a14dad0b3c806d55f8ab752e4f7921731cab0753c562499b7c88eeb8e5e8400efaab
6
+ metadata.gz: e3d9b271783e3f9c5b42aa2511c36a78814f239e848829fd347ad74fc5289b769da7264defe8af985bce500485d7e9480a240b3f9e261d70943b1ebc69cd671d
7
+ data.tar.gz: 3f91000787d5fa80570d378604a7cc28ef991585030bd1ce327b88e67dca3e4e647428d48863fc302165bcece5130cc2f140efb05fa478c2ff9443a7197a8b4e
@@ -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 +count+ elements from the beginning of the array.
10
- # Elements are removed from the end of the array if +count+ is less than 0.
11
- # Expects at least +count.abs+ elements in the array
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
- # Shifts +count+ elements from the array. Expects exactly +count+ elements
19
- # in the array
20
- def expect(count, message = nil)
21
- self.size == count or inoa(message)
22
- self
23
- end
24
-
25
- # Eats rest of the elements. Expects at least +min+ elements
26
- def consume(count, message = nil)
27
- self.size >= count or inoa(message)
28
- self
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
@@ -1,3 +1,3 @@
1
1
  module Shellopts
2
- VERSION = "2.0.0-2"
2
+ VERSION = "2.0.0-3"
3
3
  end
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.2
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-27 00:00:00.000000000 Z
11
+ date: 2020-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler