Project

hash-query

0.0
No commit activity in last 3 years
No release in over 3 years
Provides a css-like selector system for querying values out of deeply nested hashes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Hash Query

Build Status Code Climate Coverage Status Dependency Status

Provides a css-like selector system for querying values out of deeply nested hashes.

Usage

require 'hash_query'

hash = { 
  a: 1, 
  b: { 
    c: {
      d: { 
        e: 2, 
        f: 3 
      }
    },
    cc: [
      3,
      {
        g: 6,
        h: 7,
        i: => [ 8, 9, 10, 11 ]
      },
      4,
      5
    ]
  }
}

Requiring hash_query will provide two new methods, Hash#query_value and Hash#query_values. Both methods take a single string to represent a key or keys to be found in the hash.

To find a the first key match:

hash.query_value('e')   # => 2
hash.query_value('c d') # => { e: 2, f: 3 }

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request