Created
November 5, 2011 08:30
-
-
Save kanemu/1341272 to your computer and use it in GitHub Desktop.
MapからMapを作る。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def map2Map(defaultMap,map){ | |
def resultMap = [:] | |
defaultMap.each{k,v -> | |
if(v instanceof Map){ | |
resultMap[k] = map2Map(v,map) | |
}else if(v instanceof Closure){ | |
resultMap[k] = map.with(v) | |
} | |
} | |
return resultMap | |
} | |
def defaultMap = [ | |
familyName :{lastName}, | |
givenName :{firstName}, | |
zipcode :{"${location.zip1}-${location.zip2}"}, | |
address1 :{"${location.pref}${location.city}"}, | |
address2 :{"${location.address}${location.building}"}, | |
male :{sex=="male"} | |
] | |
def params = [ | |
userid :2341, | |
password :"9b2FG530", | |
firstName :"武", | |
lastName :"郷田", | |
email :"[email protected]", | |
mobileEmail :"[email protected]", | |
sex :"male", | |
birthday :"1964/6/15", | |
location :[ | |
zip1 :"176", | |
zip2 :"0002", | |
pref :"東京都", | |
city :"練馬区", | |
address :"月見台すすきヶ原3-3-1", | |
building :"", | |
], | |
contact :"090-3321-3213" | |
] | |
assert map2Map(defaultMap,params) == [ | |
familyName :"郷田", | |
givenName :"武", | |
zipcode :"176-0002", | |
address1 :"東京都練馬区", | |
address2 :"月見台すすきヶ原3-3-1", | |
male :true | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment