Skip to content

Traipse is a library that allows you to address a data structure of Hashes & Arrays using a dot notated string & wildcards. ex: 'categories.*.name'. Like X-Path but dumber.

Notifications You must be signed in to change notification settings

makenai/traipse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Traipse

Traipse allows you to address a data structure with a dot notated string. This is useful for extracting certain nodes in a data structure (expecially JSON-parsed) and storing the ‘path’ to those nodes in a database.

Installation

Traipse is available as a RubyGem:

gem install traipse

Example

data = {
  "name" => "Percival",
  "board" => {
    "name" => "cats"
  },
  "categories" => [
    { "name" => "animals" },
    { "name" => "kitties" },
    { "name" => "robots" },    
  ]
}

Traipse.find( data, 'name' ) # [ "Percival" ]
Traipse.find( data, 'board.name' ) # [ "cats" ]
Traipse.find( data, 'categories.name' ) # [ "animals", "kitties", "robots" ]
Traipse.find( data, '*.name' ) # [ "cats", "animals", "kitties", "robots" ]

Authors

  • Pawel Szymczykowski

About

Traipse is a library that allows you to address a data structure of Hashes & Arrays using a dot notated string & wildcards. ex: 'categories.*.name'. Like X-Path but dumber.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages