dorian-arguments 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9954bfae6d2589acc531515399fd72719c17e59850945789eda577bbdbf76a1
4
- data.tar.gz: a515bd1890f8bb0f69f7851b17a3e2e7c81a347ff3bdd0043d9de6f5978b375d
3
+ metadata.gz: 78900d0ea10eeae177661f62aa4449052393785c8bc7a8c45581626a5d7dc594
4
+ data.tar.gz: a6964ff2d943a71b9abcd50c6975e5c07cd5fd42052f3da9ad75f2ce0c3504b8
5
5
  SHA512:
6
- metadata.gz: f162d7069cce665ddafef2c864e4cfb97e367303624bcfa9fedd9539c0f1776292bb5b52073b0cd202e2a713b27ff18c3db53950f38008a4b54f81640db57cdf
7
- data.tar.gz: e45aaa64ba83d4c43e7b1cc08115556ded6942de9a2d85b16d1bf2b106870703347922558d5e99afdedbe65d89c1c2dcb26890d9552a645d5e136fc32bb21f1e
6
+ metadata.gz: 4930286f6f79b4755900c977e038dc2bdd39fbc2bcc17f5f80c864fd09db763756bdd725ebf3ac63a974d8dcb2fd43e4b84d52b535eb5757c3715adebe255634
7
+ data.tar.gz: 25ac436b8a6cfead0a03c1e1235d755bd7fe137e4987814de909c69e0f9fb155a3726d1d4e7a955eb8914a76b3cdf80d027412d45807e23e89419033e9380863
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
data/bin/arguments CHANGED
@@ -6,7 +6,7 @@ require "dorian/arguments"
6
6
  parsed = Dorian::Arguments.parse(version: { alias: :v }, help: { alias: :h })
7
7
 
8
8
  if parsed.options.version
9
- abort File.read(File.expand_path("../../VERSION", __FILE__))
9
+ abort File.read(File.expand_path("../VERSION", __dir__))
10
10
  else
11
11
  abort parsed.help
12
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bigdecimal"
2
4
  require "bigdecimal/util"
3
5
 
@@ -12,10 +14,10 @@ class Dorian
12
14
  DECIMAL = "decimal"
13
15
 
14
16
  DEFAULT_MULTIPLE = false
15
- DEFAULT_ALIASES = []
17
+ DEFAULT_ALIASES = [].freeze
16
18
  DEFAULT_TYPE = BOOLEAN
17
19
 
18
- TYPES = [BOOLEAN, STRING, NUMBER, INTEGER, DECIMAL]
20
+ TYPES = [BOOLEAN, STRING, NUMBER, INTEGER, DECIMAL].freeze
19
21
 
20
22
  DEFAULT = nil
21
23
 
@@ -25,9 +27,9 @@ class Dorian
25
27
  NUMBER => /^[0-9.]+$/i,
26
28
  INTEGER => /^[0-9]+$/i,
27
29
  DECIMAL => /^[0-9.]+$/i
28
- }
30
+ }.freeze
29
31
 
30
- BOOLEANS = { "true" => true, "false" => false }
32
+ BOOLEANS = { "true" => true, "false" => false }.freeze
31
33
 
32
34
  def initialize(**definition)
33
35
  @definition = definition
@@ -40,7 +42,6 @@ class Dorian
40
42
  def parse
41
43
  arguments = ARGV
42
44
  options = {}
43
- files = []
44
45
 
45
46
  definition.each do |key, value|
46
47
  type, default, aliases = normalize(value)
@@ -59,8 +60,8 @@ class Dorian
59
60
 
60
61
  if argument.include?("=")
61
62
  argument.split("=", 2).last
62
- elsif arguments[index + 1].to_s =~ MATCHES.fetch(type)
63
- indexes << index + 1
63
+ elsif arguments[index + 1].to_s&.match?(MATCHES.fetch(type))
64
+ indexes << (index + 1)
64
65
 
65
66
  arguments[index + 1]
66
67
  elsif type == BOOLEAN
@@ -70,7 +71,7 @@ class Dorian
70
71
  end
71
72
  end
72
73
  end
73
- .reject(&:nil?)
74
+ .compact
74
75
 
75
76
  indexes.sort.reverse.uniq.each { |index| arguments.delete_at(index) }
76
77
 
@@ -87,7 +88,10 @@ class Dorian
87
88
  options = Struct.new(*options.keys).new(*options.values)
88
89
 
89
90
  Struct.new(:arguments, :options, :files, :help).new(
90
- arguments, options, files, help
91
+ arguments,
92
+ options,
93
+ files,
94
+ help
91
95
  )
92
96
  end
93
97
 
@@ -98,7 +102,7 @@ class Dorian
98
102
  BOOLEANS.fetch(value.downcase)
99
103
  elsif type == INTEGER
100
104
  value.to_i
101
- elsif type == DECIMAL || type == NUMBER
105
+ elsif [DECIMAL, NUMBER].include?(type)
102
106
  value.to_d
103
107
  else
104
108
  value
@@ -106,7 +110,7 @@ class Dorian
106
110
  end
107
111
 
108
112
  def help
109
- message = "USAGE: #{$PROGRAM_NAME}\n"
113
+ message = "USAGE: #{File.basename($PROGRAM_NAME)}\n"
110
114
 
111
115
  message += "\n" if definition.any?
112
116
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-arguments
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-24 00:00:00.000000000 Z
11
+ date: 2024-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bigdecimal
@@ -46,9 +46,9 @@ require_paths:
46
46
  - lib
47
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
- - - ">="
49
+ - - '='
50
50
  - !ruby/object:Gem::Version
51
- version: '0'
51
+ version: 3.3.4
52
52
  required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="