Excise
This is a simple helper to extract values from a string based on a pattern.
A Ruby port of laktek's extract-values.
Installation
Add this line to your application's Gemfile:
gem 'excise'
And then execute:
$ bundle
Or install it yourself as:
$ gem install excise
Usage
require 'excise'
# Basic use
Excise('About {result_count} results ({load_time} seconds)',
'About 49,000,000 results (0.15 seconds)')
#=> {:result_count=>"49,000,000", :load_time=>"0.15"}
# Memoize pattern for performance improvement
pattern = Excise.new('[{key}]')
pattern.parse '[value]' #=> {:key=>"value"}
pattern.parse '[other]' #=> {:key=>"other"}
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request