Project

parsey

0.0
No commit activity in last 3 years
No release in over 3 years
Parsey matches a string with a pattern to retrieve data from it.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

parsey

Parsey is a simple class to match a string with a pattern and retrieve data from it. It takes a string, a pattern, and a hash of regular expressions (as strings). The pattern is filled with the regular expressions and then that is matched to the string given.

The pattern uses {} to surround the name of the regex it should be replaced with. You can also use <> to surround parts of the pattern that are optional, though these obviously must be nested properly.

Install

(sudo) gem install parsey

Example

partials = {'folder'    => '([a-zA-Z0-9-]+)', 
           'file-name' => '([a-zA-Z0-9_ -]+)', 
           'ext'       => '(txt|jpg|png)'}

Parsey.parse('my-folder/my file.txt', '{folder}/{file-name}.{ext}', partials)
 #=> {"folder"=>"my-folder", "file-name"=>"my file", "ext"=>"txt"}

Parsey.parse('my file.txt', '<{folder}/>{file-name}.{ext}', partials)
 #=> {"file-name"=>"my file", "ext"=>"txt"}

Copyright

Copyright (c) 2010 Joshua Hawxwell. See LICENSE for details.