Skip to content

Instantly share code, notes, and snippets.

@xet7
Created December 1, 2015 20:55
Show Gist options
  • Save xet7/b6a0cb9e12903e362e84 to your computer and use it in GitHub Desktop.
Save xet7/b6a0cb9e12903e362e84 to your computer and use it in GitHub Desktop.
Converting ruby hash to another. Mainly to get Datavalues to destination places.
Source:
{"Level1"=>
[{"Level2"=>
[{"Level3"=>[{"Data1name"=>["Data1value"]}],
"Info1"=>
[{"Data4name"=>["Data4value"],
"Data3name"=>["Data3value"],
"Data5name"=>["Data5value"],
"Info2"=>
[{"Data2name"=>"Data2value1", "content"=>"Data2value2"}]}]}]}]}
Destination:
{"auth_token"=>"something",
"items"=>
[{"label"=>"Name1", "value"=>"Data1value"},
{"label"=>"Name2", "value"=>"Data2value1+Data2value2"},
{"label"=>"Name3", "value"=>"Data3value"},
{"label"=>"Name4", "value"=>"Data4value"},
{"label"=>"Name5", "value"=>"Data5value"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment