Sha256: ff61b0c4f87d67ccd654dc53197b5c2b94294d675df8a2883d95d2878f7fed2b
Contents?: true
Size: 991 Bytes
Versions: 1
Compression:
Stored size: 991 Bytes
Contents
require 'hashie/mash' module Hashie class Unrash < Mash protected def convert_key(key) #:nodoc: camel_case_lower(key.to_s) end # Unlike its parent Mash, a Unrash will convert other Hashie::Hash values to a Unrash when assigning # instead of respecting the existing subclass def convert_value(val, duping=false) #:nodoc: case val when self.class val.dup when ::Hash val = val.dup if duping self.class.new(val) when Array val.collect{ |e| convert_value(e) } else val end end # converts a underscore string to a lowerCamelCase string def camel_case_lower(str) str.strip().gsub(' ','').split('_').inject([]){ |buffer,e| buffer.push(buffer.empty? ? e : e.capitalize) }.join end def camel_case(str) return str if str !~ /_/ && str =~ /[A-Z]+.*/ str.strip().gsub(' ','').split('_').map{|e| e.capitalize}.join end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
unrash-0.5.0 | lib/hashie/unrash.rb |