Sha256: 1f689d7d5dc4876f4d0219984b29279b2c404536a63f3bcd94bbb3238cc590c6

Contents?: true

Size: 617 Bytes

Versions: 11

Compression:

Stored size: 617 Bytes

Contents

# frozen_string_literal: true

module MailerLite
  module Utils
    BLANK_RE = /\A[[:space:]]*\z/.freeze

    class << self
      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

      def blank?(obj)
        return !!BLANK_RE.match(obj) if obj.is_a?(String)

        obj.respond_to?(:empty?) ? !!obj.empty? : !obj
      end

      def present?(obj)
        !blank?(obj)
      end

      def presence(obj)
        obj if present?(obj)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mailerlite-1.16.0 lib/mailerlite/utils.rb
mailerlite-1.15.0 lib/mailerlite/utils.rb
mailerlite-1.14.0 lib/mailerlite/utils.rb
mailerlite-1.13.1 lib/mailerlite/utils.rb
mailerlite-1.13.0 lib/mailerlite/utils.rb
mailerlite-1.12.0 lib/mailerlite/utils.rb
mailerlite-1.11.0 lib/mailerlite/utils.rb
mailerlite-1.10.0 lib/mailerlite/utils.rb
mailerlite-1.9.0 lib/mailerlite/utils.rb
mailerlite-1.8.0 lib/mailerlite/utils.rb
mailerlite-1.7.0 lib/mailerlite/utils.rb