gandalfini / hash-path Goto Github PK
View Code? Open in Web Editor NEWThis project forked from maiha/hash-path
path accessor to hierarchical hash
License: MIT License
This project forked from maiha/hash-path
path accessor to hierarchical hash
License: MIT License
hash-path ========= path accessor to hierarchical hash Class ===== * HashPath .path : define path accessor .paths : defined paths Example ======= # JSON.parse(...) returns like this hash = { "Name" => "foo", "Body" => "content", "Additional" => { "Code" => 1234, "StartDateTime"=>"2010/01/10 19:30" } } class Item < HashPath path :name, "Name" path :body, "Body" path :code, "Additional/Code" path :time, "Additional/StartDateTime" def time Time.parse(super) # parse is defined in active_support, night-time,... gem end end item = Item.new(hash) item.name # => "foo" item.code # => 1234 item.time # => Sun Jan 10 19:30:00 +0900 2010 Advanced ======== # Extends HashPath to accept jsonpath syntax for path value. # Install gem first, and then require 'hash-path/json'. # # gem install jsonpath require 'hash-path/json' hash = { "name"=>"Buono", "members"=> [{"name"=>"momo", "age"=>17}, {"name"=>"miya", "age"=>17}, {"name"=>"airi", "age"=>15}] } class Group < HashPath path :leader , "$..members[0]" path :middle_school_member, "$..members[?(@['age'] <= 15)]" end group = Group.new(hash) group.leader # => [{"name"=>"momo", "age"=>17}] group.middle_school_member # => [{"name"=>"airi", "age"=>15}] Todo ==== * convert value to some type automatically Author ====== [email protected]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.