Class: DTK::Common::PrettyPrintHash
Instance Method Summary
collapse
#initialize, #set_unless_nil
Instance Method Details
#add(model_object, *keys, &block) ⇒ Object
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
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/hash_object.rb', line 47
def add(model_object,*keys,&block)
keys.each do |key|
if key.to_s =~ /(^.+)\?$/
key = $1.to_sym
next unless model_object[key]
end
val = (key == :id ? model_object.id : model_object[key])
self[key] = (block ? block.call(val) : val)
end
self
end
|
#slice(*keys) ⇒ Object
61
62
63
|
# File 'lib/hash_object.rb', line 61
def slice(*keys)
keys.inject(self.class.new){|h,k|h.merge(k => self[k])}
end
|