dorian-arguments 1.1.0 → 1.2.0

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: f9954bfae6d2589acc531515399fd72719c17e59850945789eda577bbdbf76a1
4
- data.tar.gz: a515bd1890f8bb0f69f7851b17a3e2e7c81a347ff3bdd0043d9de6f5978b375d
3
+ metadata.gz: f09e26d0411f7f84c04ddaab79c610688bbef8cde70168e382c7e5ba0806f318
4
+ data.tar.gz: cc1076eee8faf10974beac03a902bbf687b6877a347b729dd5a4156d817a9c9d
5
5
  SHA512:
6
- metadata.gz: f162d7069cce665ddafef2c864e4cfb97e367303624bcfa9fedd9539c0f1776292bb5b52073b0cd202e2a713b27ff18c3db53950f38008a4b54f81640db57cdf
7
- data.tar.gz: e45aaa64ba83d4c43e7b1cc08115556ded6942de9a2d85b16d1bf2b106870703347922558d5e99afdedbe65d89c1c2dcb26890d9552a645d5e136fc32bb21f1e
6
+ metadata.gz: cadb685adb75738e5c25f8deb35f4108a761ba8fbc960a40c9b9da975f83c01a866fa12fc2ecb14b15e7e279ef941a8a16a82ded81b0348f5e85dd3c9a398746
7
+ data.tar.gz: 98ff574b80ed6cd988418bab196d4a0753a6e14470af260c59323703620f142a80b5285f945a1004b82c046bf838caaa822c6fc55d83dfe124a70ac5e288e456
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
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.2.0
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
  - - ">="