judges 0.13.1 → 0.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/judges.gemspec +1 -1
- data/lib/judges/options.rb +29 -24
- data/lib/judges.rb +1 -1
- data/test/test_options.rb +9 -3
- 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: 423404090687b2214385439c28e9d5aa3e916d3eab7fcad7b406e9c795750ed0
|
4
|
+
data.tar.gz: 8f5c5b7f86625a2d57f3419010ea06891ca34ae3e1332a6858bd0f3edd467f8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56b32e90fb490e8664960b113b1f4aea5ff8b5be8778aab308c3d2cfdfade484d1efbe1550f523303ff8372f6065dd581ad01c19a2b48e38b4b250052ae74332
|
7
|
+
data.tar.gz: '0578ac5a5a17b870e887e7ba6aaafafdaf51ad02b3d32fbb77857718b427550419e04c5d9711e907f2cb2b6eb7c35d58a0b5f4bc3ead36854fe6f5733c90bb8c'
|
data/judges.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
27
27
|
s.required_ruby_version = '>=3.2'
|
28
28
|
s.name = 'judges'
|
29
|
-
s.version = '0.13.
|
29
|
+
s.version = '0.13.2'
|
30
30
|
s.license = 'MIT'
|
31
31
|
s.summary = 'Command-Line Tool for a Factbase'
|
32
32
|
s.description =
|
data/lib/judges/options.rb
CHANGED
@@ -35,48 +35,53 @@ class Judges::Options
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def empty?
|
38
|
-
|
39
|
-
@hash.empty?
|
38
|
+
to_h.empty?
|
40
39
|
end
|
41
40
|
|
42
41
|
def +(other)
|
43
|
-
|
44
|
-
|
45
|
-
other.touch # this will trigger method_missing() method, which will create @hash
|
46
|
-
other.instance_variable_get(:@hash).each do |k, v|
|
42
|
+
h = to_h
|
43
|
+
other.to_h.each do |k, v|
|
47
44
|
h[k] = v
|
48
45
|
end
|
49
|
-
Judges::Options.new(h
|
46
|
+
Judges::Options.new(h)
|
50
47
|
end
|
51
48
|
|
52
49
|
# Convert them all to a string (printable in a log).
|
53
50
|
def to_s
|
54
|
-
|
55
|
-
@hash.map do |k, v|
|
51
|
+
to_h.map do |k, v|
|
56
52
|
v = v.to_s
|
57
53
|
v = "#{v[0..3]}#{'*' * (v.length - 4)}" if v.length > 8
|
58
54
|
"#{k} → \"#{v}\""
|
59
55
|
end.join("\n")
|
60
56
|
end
|
61
57
|
|
62
|
-
|
63
|
-
|
64
|
-
@hash ||= begin
|
58
|
+
def to_h
|
59
|
+
@to_h ||= begin
|
65
60
|
pp = @pairs || []
|
66
|
-
pp = @pairs.map { |k, v| "#{k}=#{v}" } if pp.is_a?(Hash)
|
67
61
|
pp = pp.split(',') if pp.is_a?(String)
|
68
|
-
pp.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
62
|
+
if pp.is_a?(Array)
|
63
|
+
pp = pp
|
64
|
+
.compact
|
65
|
+
.map(&:strip)
|
66
|
+
.reject(&:empty?)
|
67
|
+
.map { |s| s.split('=', 2) }
|
68
|
+
.map { |a| a.size == 1 ? [a[0], nil] : a }
|
69
|
+
.reject { |a| a[0].empty? }
|
70
|
+
.to_h
|
76
71
|
end
|
77
|
-
pp
|
72
|
+
pp
|
73
|
+
.reject { |k, _| k.nil? }
|
74
|
+
.reject { |k, _| k.is_a?(String) && k.empty? }
|
75
|
+
.to_h
|
76
|
+
.transform_values { |v| v.nil? ? 'true' : v }
|
77
|
+
.transform_values { |v| v.is_a?(String) ? v.strip : v }
|
78
|
+
.transform_values { |v| v.is_a?(String) && v.match?(/^[0-9]+$/) ? v.to_i : v }
|
79
|
+
.transform_keys { |k| k.to_s.strip.upcase.to_sym }
|
78
80
|
end
|
79
|
-
|
80
|
-
|
81
|
+
end
|
82
|
+
|
83
|
+
# Get option by name.
|
84
|
+
others do |*args|
|
85
|
+
to_h[args[0].upcase.to_sym]
|
81
86
|
end
|
82
87
|
end
|
data/lib/judges.rb
CHANGED
data/test/test_options.rb
CHANGED
@@ -55,7 +55,7 @@ class TestOptions < Minitest::Test
|
|
55
55
|
def test_with_empty_string
|
56
56
|
opts = Judges::Options.new(' ')
|
57
57
|
assert(opts.foo.nil?)
|
58
|
-
assert(opts.empty
|
58
|
+
assert(opts.empty?, opts)
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_with_empty_strings
|
@@ -73,14 +73,14 @@ class TestOptions < Minitest::Test
|
|
73
73
|
def test_with_hash
|
74
74
|
opts = Judges::Options.new('foo' => 42, 'bar' => 'hello')
|
75
75
|
assert_equal(42, opts.foo)
|
76
|
-
assert_equal('hello', opts.
|
76
|
+
assert_equal('hello', opts.Bar)
|
77
77
|
assert(opts.xxx.nil?)
|
78
78
|
end
|
79
79
|
|
80
80
|
def test_converts_to_string
|
81
81
|
opts = Judges::Options.new('foo' => 44, 'bar' => 'long-string-maybe-secret')
|
82
82
|
s = opts.to_s
|
83
|
-
assert(s.include?('FOO → "44"'))
|
83
|
+
assert(s.include?('FOO → "44"'), s)
|
84
84
|
assert(s.include?('"long********************"'))
|
85
85
|
end
|
86
86
|
|
@@ -91,4 +91,10 @@ class TestOptions < Minitest::Test
|
|
91
91
|
assert_equal(44, opts.a)
|
92
92
|
assert_equal(3, opts.c)
|
93
93
|
end
|
94
|
+
|
95
|
+
def test_merge_by_symbols
|
96
|
+
opts = Judges::Options.new(a: 42) + Judges::Options.new(b: 7)
|
97
|
+
assert_equal(42, opts.a, opts)
|
98
|
+
assert_equal(7, opts.b, opts)
|
99
|
+
end
|
94
100
|
end
|