more_core_extensions 4.2.0 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -2
- data/README.md +6 -0
- data/lib/more_core_extensions/core_ext/object.rb +1 -0
- data/lib/more_core_extensions/core_ext/object/deep_send.rb +28 -0
- data/lib/more_core_extensions/core_ext/string.rb +1 -0
- data/lib/more_core_extensions/core_ext/string/to_i_with_method.rb +87 -0
- data/lib/more_core_extensions/version.rb +1 -1
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b7f22572ca60d54c6ae412b47afec772d698d9289f047736abec4cff3204d03
|
4
|
+
data.tar.gz: 51037bedd097a1d44a590c4a4502e42a2bc79841ca240fdc8ae429bb7887114d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f5a9444c922416547bfb24e4a3efcb9bda6fcecccd29f38a2ac12c637ee463018c80d51d68695a822c76030066d2f04731e3eb9a40edea141f6f1ddf7ce5e13
|
7
|
+
data.tar.gz: 9077ad1ea1242be1e82293ee5698b457d70962c9c405c0df127ae796000c2b1b29749906d7d5ef41fece1163205b2c508f129a33e0b342512c68f144a329a2c6
|
data/CHANGELOG.md
CHANGED
@@ -4,13 +4,18 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
5
5
|
## [Unreleased]
|
6
6
|
|
7
|
+
## [4.3.0] - 2020-10-27
|
8
|
+
### Added
|
9
|
+
- Add String#to_i_with_method and friends [[#95](https://github.com/ManageIQ/more_core_extensions/pull/95)]
|
10
|
+
- Add Object#deep_send [[#94](https://github.com/ManageIQ/more_core_extensions/pull/94)]
|
11
|
+
|
7
12
|
## [4.2.0] - 2020-07-20
|
8
13
|
### Added
|
9
14
|
- Add bundler-inject allowing developers to override dependencies [[#89](https://github.com/ManageIQ/more_core_extensions/pull/89)]
|
10
15
|
- Add Array and Hash #deep_clone and #deep_delete [[#91](https://github.com/ManageIQ/more_core_extensions/pull/91)]
|
11
16
|
- Add Digest::UUID.clean to properly format UUID strings [[#81](https://github.com/ManageIQ/more_core_extensions/pull/81)]
|
12
17
|
|
13
|
-
###Changed
|
18
|
+
### Changed
|
14
19
|
- Update ArrayTableize to properly set field width for color text [[#87](https://github.com/ManageIQ/more_core_extensions/pull/87)]
|
15
20
|
- Change Array#format_table header output to markdown vs postgres [[#83](https://github.com/ManageIQ/more_core_extensions/pull/83)]
|
16
21
|
|
@@ -97,7 +102,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
97
102
|
- Upgraded to RSpec 3 [[#16](https://github.com/ManageIQ/more_core_extensions/pull/16)]
|
98
103
|
- Added the Change Log!
|
99
104
|
|
100
|
-
[Unreleased]: https://github.com/ManageIQ/more_core_extensions/compare/v4.
|
105
|
+
[Unreleased]: https://github.com/ManageIQ/more_core_extensions/compare/v4.3.0...HEAD
|
106
|
+
[4.3.0]: https://github.com/ManageIQ/more_core_extensions/compare/v4.2.0...v4.3.0
|
101
107
|
[4.2.0]: https://github.com/ManageIQ/more_core_extensions/compare/v4.1.0...v4.2.0
|
102
108
|
[4.1.0]: https://github.com/ManageIQ/more_core_extensions/compare/v4.0.0...v4.1.0
|
103
109
|
[4.0.0]: https://github.com/ManageIQ/more_core_extensions/compare/v3.8.0...v4.0.0
|
data/README.md
CHANGED
@@ -89,6 +89,8 @@ MoreCoreExtensions are a set of core extensions beyond those provided by ActiveS
|
|
89
89
|
|
90
90
|
#### Object
|
91
91
|
|
92
|
+
* core_ext/module/deep_send.rb
|
93
|
+
* `#deep_send` - Invokes the specified methods continuously, unless encountering a nil value.
|
92
94
|
* core_ext/module/namespace.rb
|
93
95
|
* `#in_namespace?` - Returns whether or not the object is in the given namespace
|
94
96
|
|
@@ -122,6 +124,10 @@ MoreCoreExtensions are a set of core extensions beyond those provided by ActiveS
|
|
122
124
|
* `#hex_dump` - Dumps the string in a hex editor style format
|
123
125
|
* core_ext/string/iec60027_2.rb
|
124
126
|
* `#iec_60027_2_to_i` - Convert strings with an IEC60027-2 suffix to an integer
|
127
|
+
* core_ext/string/to_i_with_method.rb
|
128
|
+
* `#to_f_with_method` - Converts to a Float while also evaluating a method invocation
|
129
|
+
* `#to_i_with_method` - Converts to an Integer while also evaluating a method invocation
|
130
|
+
* `#number_with_method?` - Determines if the object contains a number with a method invocation
|
125
131
|
|
126
132
|
#### Symbol
|
127
133
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MoreCoreExtensions
|
2
|
+
module ObjectDeepSend
|
3
|
+
#
|
4
|
+
# Invokes the specified methods continuously, unless encountering a nil value.
|
5
|
+
#
|
6
|
+
# 10.deep_send("to_s.length") # => 2
|
7
|
+
# 10.deep_send("to_s", "length") # => 2
|
8
|
+
# 10.deep_send(:to_s, :length) # => 2
|
9
|
+
# 10.deep_send(["to_s", "length"]) # => 2
|
10
|
+
# [].deep_send("first.length") # => nil
|
11
|
+
#
|
12
|
+
def deep_send(*args)
|
13
|
+
args = args.first.dup if args.length == 1 && args.first.kind_of?(Array)
|
14
|
+
args = args.shift.to_s.strip.split('.') + args
|
15
|
+
|
16
|
+
arg = args.shift
|
17
|
+
raise ArgumentError if arg.nil?
|
18
|
+
|
19
|
+
result = send(arg)
|
20
|
+
return nil if result.nil?
|
21
|
+
return result if args.empty?
|
22
|
+
|
23
|
+
result.deep_send(args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Object.send(:include, MoreCoreExtensions::ObjectDeepSend)
|
@@ -2,3 +2,4 @@ require 'more_core_extensions/core_ext/string/formats'
|
|
2
2
|
require 'more_core_extensions/core_ext/string/hex_dump'
|
3
3
|
require 'more_core_extensions/core_ext/string/iec60027_2'
|
4
4
|
require 'more_core_extensions/core_ext/string/decimal_suffix'
|
5
|
+
require 'more_core_extensions/core_ext/string/to_i_with_method'
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module MoreCoreExtensions
|
2
|
+
module StringToIWithMethod
|
3
|
+
NUMBER_WITH_METHOD_REGEX = /^([0-9\.,]+)\.([a-z]+)$/.freeze
|
4
|
+
|
5
|
+
# Converts to an Integer while also evaluating a method invocation
|
6
|
+
#
|
7
|
+
# This method is similar to #to_i, but does not support extraneous characters
|
8
|
+
# nor bases other than 10.
|
9
|
+
#
|
10
|
+
# "20".to_i_with_method # => 20
|
11
|
+
# "20.percent".to_i_with_method # => 20
|
12
|
+
# "20.megabytes".to_i_with_method # => 20_971_520
|
13
|
+
#
|
14
|
+
# "20.0".to_i_with_method # => 20
|
15
|
+
# "20.0.percent".to_i_with_method # => 20
|
16
|
+
# "20.0.megabytes".to_i_with_method # => 20_971_520
|
17
|
+
#
|
18
|
+
# 20.to_i_with_method # => 20
|
19
|
+
# 20.0.to_i_with_method # => 20
|
20
|
+
# nil.to_i_with_method # => 0
|
21
|
+
#
|
22
|
+
def to_i_with_method
|
23
|
+
to_x_with_method.to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
# Converts to a Float while also evaluating a method invocation
|
27
|
+
#
|
28
|
+
# This method is similar to #to_f, but does not support extraneous characters.
|
29
|
+
#
|
30
|
+
# "20".to_f_with_method # => 20.0
|
31
|
+
# "20.percent".to_f_with_method # => 20.0
|
32
|
+
# "20.megabytes".to_f_with_method # => 20_971_520.0
|
33
|
+
#
|
34
|
+
# "20.1".to_f_with_method # => 20.1
|
35
|
+
# "20.1.percent".to_f_with_method # => 20.1
|
36
|
+
# "20.1.megabytes".to_f_with_method # => 21_076_377.6
|
37
|
+
#
|
38
|
+
# 20.to_f_with_method # => 20.0
|
39
|
+
# 20.1.to_f_with_method # => 20.1
|
40
|
+
# nil.to_f_with_method # => 0.0
|
41
|
+
#
|
42
|
+
def to_f_with_method
|
43
|
+
to_x_with_method.to_f
|
44
|
+
end
|
45
|
+
|
46
|
+
private def to_x_with_method
|
47
|
+
n = delete(',')
|
48
|
+
return n unless n =~ NUMBER_WITH_METHOD_REGEX && $2 != "percent"
|
49
|
+
|
50
|
+
n = $1.include?('.') ? $1.to_f : $1.to_i
|
51
|
+
n.send($2)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Determines if the object contains a number with a method invocation
|
55
|
+
#
|
56
|
+
# "20".number_with_method? # => false
|
57
|
+
# "20.percent".number_with_method? # => true
|
58
|
+
# "20.0.percent".number_with_method? # => true
|
59
|
+
def number_with_method?
|
60
|
+
self =~ NUMBER_WITH_METHOD_REGEX
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module NumericAndNilToIWithMethod
|
65
|
+
# See String#to_i_with_method
|
66
|
+
def to_i_with_method
|
67
|
+
to_i
|
68
|
+
end
|
69
|
+
|
70
|
+
# See String#to_f_with_method
|
71
|
+
def to_f_with_method
|
72
|
+
to_f
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
module ObjectToIWithMethod
|
77
|
+
# See String#number_with_method?
|
78
|
+
def number_with_method?
|
79
|
+
false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
String.send(:prepend, MoreCoreExtensions::StringToIWithMethod)
|
85
|
+
Numeric.send(:prepend, MoreCoreExtensions::NumericAndNilToIWithMethod)
|
86
|
+
NilClass.send(:prepend, MoreCoreExtensions::NumericAndNilToIWithMethod)
|
87
|
+
Object.send(:prepend, MoreCoreExtensions::ObjectToIWithMethod)
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: more_core_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Frey
|
8
8
|
- Brandon Dunne
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-10-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -178,6 +178,7 @@ files:
|
|
178
178
|
- lib/more_core_extensions/core_ext/numeric/math.rb
|
179
179
|
- lib/more_core_extensions/core_ext/numeric/rounding.rb
|
180
180
|
- lib/more_core_extensions/core_ext/object.rb
|
181
|
+
- lib/more_core_extensions/core_ext/object/deep_send.rb
|
181
182
|
- lib/more_core_extensions/core_ext/object/namespace.rb
|
182
183
|
- lib/more_core_extensions/core_ext/process.rb
|
183
184
|
- lib/more_core_extensions/core_ext/process/pause_resume.rb
|
@@ -189,6 +190,7 @@ files:
|
|
189
190
|
- lib/more_core_extensions/core_ext/string/formats.rb
|
190
191
|
- lib/more_core_extensions/core_ext/string/hex_dump.rb
|
191
192
|
- lib/more_core_extensions/core_ext/string/iec60027_2.rb
|
193
|
+
- lib/more_core_extensions/core_ext/string/to_i_with_method.rb
|
192
194
|
- lib/more_core_extensions/core_ext/symbol.rb
|
193
195
|
- lib/more_core_extensions/core_ext/symbol/to_i.rb
|
194
196
|
- lib/more_core_extensions/version.rb
|
@@ -197,7 +199,7 @@ homepage: http://github.com/ManageIQ/more_core_extensions
|
|
197
199
|
licenses:
|
198
200
|
- MIT
|
199
201
|
metadata: {}
|
200
|
-
post_install_message:
|
202
|
+
post_install_message:
|
201
203
|
rdoc_options: []
|
202
204
|
require_paths:
|
203
205
|
- lib
|
@@ -212,8 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
214
|
- !ruby/object:Gem::Version
|
213
215
|
version: '0'
|
214
216
|
requirements: []
|
215
|
-
rubygems_version: 3.0.
|
216
|
-
signing_key:
|
217
|
+
rubygems_version: 3.0.3
|
218
|
+
signing_key:
|
217
219
|
specification_version: 4
|
218
220
|
summary: MoreCoreExtensions are a set of core extensions beyond those provided by
|
219
221
|
ActiveSupport.
|