trick_bag 0.58.0 → 0.58.1

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
  SHA1:
3
- metadata.gz: 10d4086b2610d6e23ce59201321b731e05a74df3
4
- data.tar.gz: f64bd3abeeb2ee2c948173d39fb2cb1e464d5111
3
+ metadata.gz: 3bc667fb430486e4cc7923ea12c615bc658cdd7e
4
+ data.tar.gz: 4db0fde0dd906dda2a46ebacb975908ac18eb154
5
5
  SHA512:
6
- metadata.gz: f36e566103aee54e599824f739a23b02c2a9957cfd857d4cc2c91d5aa086d3371638d61628766439569c4562f09e9fa182a95b20128b3c1e23b8624ea54429d1
7
- data.tar.gz: 43ba1d249627e9205dc853d9fbde3e0bed51b1931cc5a28819bb6da64dbafb48cda72ee063578969926265deff5ea7384a9014ab40e8984429dac56d8bcf3750
6
+ metadata.gz: f51ab665365c45131ac6f90932a58c2f33d604ea2ce13ad00cd0eac622b4816ece6e79d0ced9e73d487fed1ff71ec071a485e54f87bb890387b194a08d6d3d68
7
+ data.tar.gz: 44d8d27beb484babc4be8a78f773129ac0d2c790a989208c23fd2ac233a0634cc79fc5fa055b19f5b7a25cbdac53f3fd1cdb5e3e9710dd9f49add4898b11bdc6
data/RELEASE_NOTES.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.58.1
2
+
3
+ * For KmgtNumericString, support returning of nil/false on nil input.
4
+
5
+
1
6
  ## v0.58.0
2
7
 
3
8
  * Added KmbtNumericString, Formatters.thousands_separated.
@@ -35,18 +35,19 @@ module KmgtNumericString
35
35
  object.is_a?(String) ? ToNumberConverter.new(object).to_number : object
36
36
  end
37
37
 
38
- # Returns whether or not this is a number range. Specifically, tests that
38
+ # Returns whether or not this is a number range string. Specifically, tests that
39
39
  # the string contains only 2 numeric strings separated by '..'.
40
40
  def range_string?(string)
41
+ return false unless string.is_a?(String)
41
42
  number_strings = string.split('..')
42
43
  number_strings.size == 2 && number_strings.all? { |str| VALID_STRING_REGEX.match(str) }
43
44
  end
44
45
 
45
46
  # Converts the passed string to a range (see range_string? above for the string's format).
46
- # If the passed parameter is a Range already, returns it unchanged.
47
+ # If the passed parameter is nil or is a Range already, returns it unchanged.
47
48
  # This eliminates the need for the caller to do their own type test.
48
49
  def to_range(object)
49
- return object if object.is_a?(Range)
50
+ return object if object.is_a?(Range) || object.nil?
50
51
  unless range_string?(object)
51
52
  raise ArgumentError.new("Invalid argument (#{object}); Range must be 2 numbers separated by '..', e.g. 10..20 or 900K..1M")
52
53
  end
@@ -55,11 +56,11 @@ module KmgtNumericString
55
56
  end
56
57
 
57
58
  # Converts a string such as '3' or '1k..2k' into a number or range.
58
- # If an Integer or Range is passed, it is returned unchanged.
59
+ # If nil or an Integer or Range is passed, it is returned unchanged.
59
60
  # This eliminates the need for the caller to do their own type test.
60
61
  def to_number_or_range(object)
61
62
  case object
62
- when Integer, Range
63
+ when Integer, Range, NilClass
63
64
  object
64
65
  when String
65
66
  range_string?(object) ? to_range(object) : to_number(object)
@@ -1,3 +1,3 @@
1
1
  module TrickBag
2
- VERSION = "0.58.0"
2
+ VERSION = "0.58.1"
3
3
  end
@@ -39,6 +39,10 @@ end
39
39
  expect(to_number('-10k')).to eq(-10 * 1000)
40
40
  expect(to_number('-10')).to eq(-10)
41
41
  end
42
+
43
+ specify 'nil is returned unchanged' do
44
+ expect(to_number(nil)).to eq(nil)
45
+ end
42
46
  end
43
47
 
44
48
 
@@ -58,6 +62,10 @@ end
58
62
  expect(range_string?('-1..1')).to eq(true)
59
63
  expect(range_string?('10K..10M')).to eq(true)
60
64
  end
65
+
66
+ specify 'nil returns false' do
67
+ expect(range_string?(nil)).to eq(false)
68
+ end
61
69
  end
62
70
 
63
71
 
@@ -70,6 +78,10 @@ end
70
78
  specify 'ascending ranges are supported' do
71
79
  expect(to_range('3k..4k')).to eq((3000..4000))
72
80
  end
81
+
82
+ specify 'nil is returned unchanged' do
83
+ expect(to_range(nil)).to eq(nil)
84
+ end
73
85
  end
74
86
 
75
87
  context '.to_number_or_range' do
@@ -78,6 +90,10 @@ end
78
90
  expect(to_number_or_range('12k')).to eq(12_000)
79
91
  expect(to_number_or_range('12k..24k')).to eq(12_000..24_000)
80
92
  end
93
+
94
+ specify 'nil is returned unchanged' do
95
+ expect(to_number_or_range(nil)).to eq(nil)
96
+ end
81
97
  end
82
98
  end
83
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trick_bag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.58.0
4
+ version: 0.58.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Bennett