Last active
February 10, 2018 20:30
-
-
Save baweaver/f9e19a8114dc02bb7b8b68b92e20e2aa to your computer and use it in GitHub Desktop.
Hahahahahahahahaha
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
➜ 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
https://github.com/baweaver/hashiform/blob/master/spec/hashiform_spec.rb