Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/clearbooks/core_ext/hash.rb
Instance Method Summary collapse
- #camelize_keys ⇒ Object
- #compact ⇒ Object
- #except(*keys) ⇒ Object
- #from_savon ⇒ Object
- #savon(key) ⇒ Object
Instance Method Details
#camelize_keys ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/clearbooks/core_ext/hash.rb', line 47 def camelize_keys self.inject(Hash.new) do |h, (k, v)| kk = k.to_s.camelize :lower kk = kk.to_sym if k.is_a? Symbol h[kk] = v h end end |
#compact ⇒ Object
19 20 21 |
# File 'lib/clearbooks/core_ext/hash.rb', line 19 def compact delete_if { |k, v| v.nil? } end |
#except(*keys) ⇒ Object
11 12 13 14 15 |
# File 'lib/clearbooks/core_ext/hash.rb', line 11 def except(*keys) copy = self.dup keys.each { |key| copy.delete(key) } copy end |
#from_savon ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/clearbooks/core_ext/hash.rb', line 36 def from_savon self.reduce({}) do |hash, (k, v)| k = k.to_s k = k[1..-1] if k.start_with? '@' hash[k.to_sym] = v hash end end |
#savon(key) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/clearbooks/core_ext/hash.rb', line 25 def savon(key) v = self[key] || self["@#{(key.to_s)}".to_sym] if (v.is_a? Hash) v.from_savon else v end end |