class DTK::Common::PrettyPrintHash

Public Instance Methods

add(model_object,*keys,&block) click to toggle source

field with '?' suffix means optioanlly add depending on whether name present and non-null in source if block is given then apply to source rather than returning just source

# File lib/hash_object.rb, line 47
def add(model_object,*keys,&block)
  keys.each do |key|
    #if marked as optional skip if not present
    if key.to_s =~ /(^.+)\?$/
      key = $1.to_sym
      next unless model_object[key]
    end
    #special treatment of :id
    val = (key == :id ? model_object.id : model_object[key]) 
    self[key] = (block ? block.call(val) : val)
  end
  self
end
slice(*keys) click to toggle source
# File lib/hash_object.rb, line 61
def slice(*keys)
  keys.inject(self.class.new){|h,k|h.merge(k => self[k])}
end