class Hash
monkey patch Hash
class to support reverse_merge
and collect_attributes
Public Instance Methods
attribute_post_processing()
click to toggle source
# File lib/plotrb/base.rb, line 155 def attribute_post_processing # nothing to do for Hash end
classify(name, format=nil)
click to toggle source
# File lib/plotrb/base.rb, line 180 def classify(name, format=nil) klass = name.to_s.split('_').collect(&:capitalize).join if format == :json klass[0].downcase + klass[1..-1] else klass end end
collect_attributes()
click to toggle source
# File lib/plotrb/base.rb, line 163 def collect_attributes collected = {} self.each do |k, v| json_attr = classify(k, :json) if v.respond_to?(:collect_attributes) collected[json_attr] = v.collect_attributes elsif v.is_a?(Array) collected[json_attr] = [].concat(v.collect{ |va| va.respond_to?(:collect_attributes) ? va.collect_attributes : va }) else collected[json_attr] = v end end collected end
reverse_merge(other_hash)
click to toggle source
# File lib/plotrb/base.rb, line 159 def reverse_merge(other_hash) other_hash.merge(self) end