Sha256: 3654903ab74b28b58e4d0f138f3dc17c21ede36ff87cab6cd5c95a76b18e26bb

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

## String

class String #:nodoc

  def permalink
    self.to_ascii.parameterize('-')
  end

  def permalink!
    replace(self.permalink)
  end

  alias :parameterize! :permalink!

end

## Hash

class Hash #:nodoc

  def underscore_keys
    new_hash = {}

    self.each_pair do |key, value|
      if value.respond_to?(:collect!) # Array
        value.collect do |item|
          if item.respond_to?(:each_pair) # Hash item within
            item.underscore_keys
          else
            item
          end
        end
      elsif value.respond_to?(:each_pair) # Hash
        value = value.underscore_keys
      end

      new_key = key.is_a?(String) ? key.underscore : key # only String keys

      new_hash[new_key] = value
    end

    self.replace(new_hash)
  end

end

class Boolean #:nodoc
  BOOLEAN_MAP = {
    true => true, "true" => true, "TRUE" => true, "1" => true, 1 => true, 1.0 => true,
    false => false, "false" => false, "FALSE" => false, "0" => false, 0 => false, 0.0 => false
  }

  def self.set(value)
    value = BOOLEAN_MAP[value]
    value.nil? ? nil : value
  end

  def self.get(value)
    value
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
tribeca_cms-0.1.1 lib/locomotive/core_ext.rb
tribeca_cms-2.0.0.rc12 lib/locomotive/core_ext.rb
locomotive_cms-2.0.0.rc12 lib/locomotive/core_ext.rb
locomotive_cms-2.0.0.rc11 lib/locomotive/core_ext.rb
locomotive_cms-2.0.0.rc10 lib/locomotive/core_ext.rb
locomotive_cms-2.0.0.rc9 lib/locomotive/core_ext.rb
locomotive_cms-2.0.0.rc8 lib/locomotive/core_ext.rb
locomotive_cms-2.0.0.rc7 lib/locomotive/core_ext.rb
locomotive_cms-2.0.0.rc6 lib/locomotive/core_ext.rb
locomotive_cms-2.0.0.rc5 lib/locomotive/core_ext.rb