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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e42894e95397d8b62afd1deaf3407d31321475e378f4ebdfd88216571ff742d
4
- data.tar.gz: d59aaa5f47aa2f7373b78e36869bc09aacd1c52f881c910c45d292407c3da203
3
+ metadata.gz: 423404090687b2214385439c28e9d5aa3e916d3eab7fcad7b406e9c795750ed0
4
+ data.tar.gz: 8f5c5b7f86625a2d57f3419010ea06891ca34ae3e1332a6858bd0f3edd467f8f
5
5
  SHA512:
6
- metadata.gz: 1be5c4aad65f212b8bc700616851356ccf331be5b51a1ccc1e2d9d71e2225c8f648d0604e4ae5b1957d4b0623d43b8de6e78da2a8b1ed5ecdbbbe6db9eba3fc4
7
- data.tar.gz: 8174ac41e04c618635c868b06164b79939cc2891066bda8063f806f9395b8985a650eab5770fd778fe86ad7f42d8f9496f46331a3cff175d570f39d0af2e00a2
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.1'
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 =
@@ -35,48 +35,53 @@ class Judges::Options
35
35
  end
36
36
 
37
37
  def empty?
38
- touch # this will trigger method_missing() method, which will create @hash
39
- @hash.empty?
38
+ to_h.empty?
40
39
  end
41
40
 
42
41
  def +(other)
43
- touch # this will trigger method_missing() method, which will create @hash
44
- h = @hash.dup
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.map { |k, v| "#{k}=#{v}" })
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
- touch # this will trigger method_missing() method, which will create @hash
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
- # Get option by name.
63
- others do |*args|
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.compact!
69
- pp.reject!(&:empty?)
70
- pp.map! do |pair|
71
- p = pair.split('=', 2)
72
- k = p[0].strip.upcase
73
- v = p[1]
74
- v = v.nil? ? 'true' : v.strip
75
- [k.to_sym, v.match?(/^[0-9]+$/) ? v.to_i : v]
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.reject { |p| p[0].empty? }.to_h
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
- k = args[0].upcase
80
- @hash[k]
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
@@ -25,5 +25,5 @@
25
25
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
26
26
  # License:: MIT
27
27
  module Judges
28
- VERSION = '0.13.1'
28
+ VERSION = '0.13.2'
29
29
  end
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.bar)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.1
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko