Module: Kirei::Helpers
- Extended by:
- T::Sig
- Defined in:
- lib/kirei/helpers.rb
Class Method Summary collapse
- .blank?(string) ⇒ Boolean
- .deep_stringify_keys(object) ⇒ Object
- .deep_stringify_keys!(object) ⇒ Object
- .deep_symbolize_keys(object) ⇒ Object
- .deep_symbolize_keys!(object) ⇒ Object
- .underscore(string) ⇒ Object
Class Method Details
.blank?(string) ⇒ Boolean
22 23 24 |
# File 'lib/kirei/helpers.rb', line 22 def blank?(string) string.nil? || string.to_s.empty? end |
.deep_stringify_keys(object) ⇒ Object
27 28 29 |
# File 'lib/kirei/helpers.rb', line 27 def deep_stringify_keys(object) deep_transform_keys(object) { _1.to_s rescue _1 } # rubocop:disable Style/RescueModifier end |
.deep_stringify_keys!(object) ⇒ Object
32 33 34 |
# File 'lib/kirei/helpers.rb', line 32 def deep_stringify_keys!(object) deep_transform_keys!(object) { _1.to_s rescue _1 } # rubocop:disable Style/RescueModifier end |
.deep_symbolize_keys(object) ⇒ Object
37 38 39 |
# File 'lib/kirei/helpers.rb', line 37 def deep_symbolize_keys(object) deep_transform_keys(object) { _1.to_sym rescue _1 } # rubocop:disable Style/RescueModifier end |
.deep_symbolize_keys!(object) ⇒ Object
42 43 44 |
# File 'lib/kirei/helpers.rb', line 42 def deep_symbolize_keys!(object) deep_transform_keys!(object) { _1.to_sym rescue _1 } # rubocop:disable Style/RescueModifier end |
.underscore(string) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/kirei/helpers.rb', line 11 def underscore(string) string.gsub!(/([A-Z])(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do T.must((::Regexp.last_match(1) || ::Regexp.last_match(2))) << "_" end string.tr!("-", "_") string.downcase! string end |