Sha256: 239f495811443246ee8f8f149f2201f952f6eeeb8acef966815ca65b597694c0

Contents?: true

Size: 903 Bytes

Versions: 9

Compression:

Stored size: 903 Bytes

Contents

unless String.public_instance_methods.include?(:to_bool)
  class String

    def to_bool
      return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
      return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)

      raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
    end

  end
end

unless String.public_instance_methods.include?(:permalink)
  require 'stringex'

  class String

    def permalink(underscore = false)
      # if the slug includes one "_" at least, we consider that the "_" is used instead of "-".
      _permalink = if !self.index('_').nil?
        self.to_url(replace_whitespace_with: '_')
      else
        self.to_url
      end

      underscore ? _permalink.underscore : _permalink
    end

    def permalink!(underscore = false)
      replace(self.permalink(underscore))
    end

    alias :parameterize! :permalink!

  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
locomotivecms_common-0.4.0 lib/locomotive/common/core_ext/string.rb
locomotivecms_common-0.3.1 lib/locomotive/common/core_ext/string.rb
locomotivecms_common-0.3.0 lib/locomotive/common/core_ext/string.rb
locomotivecms_common-0.2.0 lib/locomotive/common/core_ext/string.rb
locomotivecms_common-0.1.0 lib/locomotive/common/core_ext/string.rb
locomotivecms_common-0.0.5 lib/locomotive/common/core_ext/string.rb
locomotivecms_common-0.0.4 lib/locomotive/common/core_ext/string.rb
locomotivecms_common-0.0.3 lib/locomotive/common/core_ext/string.rb
locomotivecms_steam-1.0.0.pre.alpha lib/locomotive/steam/core_ext/string.rb