Module: Utils::Hasher
- Included in:
- AwsMust::AwsMust
- Defined in:
- lib/utils/hasher.rb
Instance Method Summary collapse
-
#addComma(obj) ⇒ Object
adds comma hash in arrays deeply in obj-hash.
- #dfs(hsh) {|hsh| ... } ⇒ Object
Instance Method Details
#addComma(obj) ⇒ Object
adds comma hash in arrays deeply in obj-hash
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/utils/hasher.rb', line 58 def addComma( obj ) if ( obj.is_a?(Hash) ) obj2 = dfs(obj) do |o| o.each do |k,v| if v.is_a? Array # add _comma = ',', expect to the v.slice(0,v.length-1).each do |elem| elem["_comma"] = "," if elem.is_a? Hash end # add _comma = '' to the last element v.last["_comma"] = "" if v.last.is_a? Hash end end end # block obj = obj2 end return obj end |
#dfs(hsh) {|hsh| ... } ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/utils/hasher.rb', line 37 def dfs(hsh, &blk) return enum_for(:dfs, hsh) unless blk # no change unless a hash return hsh unless hsh.is_a? Hash yield hsh hsh.each do |k,v| if v.is_a? Array v.each do |elm| dfs(elm, &blk) end elsif v.is_a? Hash dfs(v, &blk) end end return hsh # nil end |