Sha256: 8fd6b9a0bab7f36599fe8d9aafa25f6457fa6e7dd7afcd171f22a5d7861ed111

Contents?: true

Size: 909 Bytes

Versions: 106

Compression:

Stored size: 909 Bytes

Contents

class Hash
  # convert hash to string like class="class val" name='name val'
  def to_attr_format(split = " ")
    res = []
    self.each do |key, value|
      res << "#{key} = \"#{value.to_s.gsub('"', '\"')}\""
    end
    res.join(split)
  end

  # convert hash to attributes for url_path
  def to_attr_url_format
    res = []
    self.each do |key, value|
      res << ":#{key} => \"#{value.to_s.gsub('"', '\"')}\""
    end
    res.join ","
  end

  # used for hash of objects
  def find_by(val, attr = "id")
    self.each do |key, p|
      if p[attr].to_s == val.to_s
        return p
      end
    end
    nil
  end

  def to_sym
    symbolize(self)
  end

  private
  def symbolize(obj)
    return obj.inject({}){|memo,(k,v)| memo[k.to_sym] =  symbolize(v); memo} if obj.is_a? Hash
    return obj.inject([]){|memo,v    | memo           << symbolize(v); memo} if obj.is_a? Array
    return obj
  end

end

Version data entries

106 entries across 106 versions & 2 rubygems

Version Path
camaleon_cms-2.6.4 lib/ext/hash.rb
camaleon_cms-2.6.3 lib/ext/hash.rb
camaleon_cms-2.6.2 lib/ext/hash.rb
camaleon_cms-2.6.1 lib/ext/hash.rb
camaleon_cms-2.6.0.1 lib/ext/hash.rb
camaleon_cms-2.6.0 lib/ext/hash.rb
camaleon_cms-2.5.3.1 lib/ext/hash.rb
camaleon_cms-2.5.3 lib/ext/hash.rb
camaleon_cms-2.5.2 lib/ext/hash.rb
camaleon_cms_rails6-2.5.0 lib/ext/hash.rb
camaleon_cms-2.5.1 lib/ext/hash.rb
camaleon_cms-2.5.0 lib/ext/hash.rb
camaleon_cms-2.4.6.9 lib/ext/hash.rb
camaleon_cms-2.4.6.8 lib/ext/hash.rb
camaleon_cms-2.4.6.7 lib/ext/hash.rb
camaleon_cms-2.4.6.6 lib/ext/hash.rb
camaleon_cms-2.4.6.5 lib/ext/hash.rb
camaleon_cms-2.4.6.4 lib/ext/hash.rb
camaleon_cms-2.4.6.3 lib/ext/hash.rb
camaleon_cms-2.4.6.2 lib/ext/hash.rb