Module: MailerLite::Utils
- Defined in:
- lib/mailerlite/utils.rb
Constant Summary collapse
- BLANK_RE =
/\A[[:space:]]*\z/.freeze
Class Method Summary collapse
- .blank?(obj) ⇒ Boolean
- .presence(obj) ⇒ Object
- .present?(obj) ⇒ Boolean
- .underscore(string) ⇒ Object
Class Method Details
.blank?(obj) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/mailerlite/utils.rb', line 16 def blank?(obj) return !!BLANK_RE.match(obj) if obj.is_a?(String) obj.respond_to?(:empty?) ? !!obj.empty? : !obj end |
.presence(obj) ⇒ Object
26 27 28 |
# File 'lib/mailerlite/utils.rb', line 26 def presence(obj) obj if present?(obj) end |
.present?(obj) ⇒ Boolean
22 23 24 |
# File 'lib/mailerlite/utils.rb', line 22 def present?(obj) !blank?(obj) end |
.underscore(string) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/mailerlite/utils.rb', line 8 def underscore(string) string.gsub('::', '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end |