Skip to content

Instantly share code, notes, and snippets.

@baweaver
Last active February 10, 2018 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baweaver/f9e19a8114dc02bb7b8b68b92e20e2aa to your computer and use it in GitHub Desktop.
Save baweaver/f9e19a8114dc02bb7b8b68b92e20e2aa to your computer and use it in GitHub Desktop.
Hahahahahahahahaha
➜ hashiform git:(master) ✗ pry --gem
[1] pry(main)>
[1] pry(main)> require 'json'; require'net/http'
=> true
[2] pry(main)> users = JSON.parse(Net::HTTP.get(URI('https://jsonplaceholder.typicode.com/users')));
[3] pry(main)> posts = JSON.parse(Net::HTTP.get(URI('https://jsonplaceholder.typicode.com/posts')));
[4] pry(main)> def user_xform(u, posts)
Hashiform.new(u,{
'get_posts' => -> user_id { posts.select { |p| p['userId'] == user_id } }
}).transform({
'name'=>'name',
'posts'=>'get_posts:id'
})
end
=> :user_xform
# ... mistakes were made
[7] pry(main)> users.map { |u| user_xform(u,posts) }
=> [{"name"=>"Leanne Graham",
"posts"=>
[{"userId"=>1,
"id"=>1,
"title"=>"sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body"=>
"quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet archite
cto"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment