Habakiri
Habariki is a template match engine for strings that can extract part of text by template keywords.
Installation
Add this line to your application's Gemfile:
gem 'habakiri'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install habakiri
Usage
require 'habakiri'
template = "YOUR NAME\uFF1A{{name}}\nEMAIL:{{email}}\nTELEPHONE NUMBER\uFF1A{{tel}}\nWebsite URL\uFF1A{{url}}\nZIP CODE\uFF1A{{zipcode}}\nADDRESS:{{address}}\nNOTE\uFF1A{{note}}\n"
text = "YOUR NAME\uFF1AJohn\nEMAIL:[email protected]\nTELEPHONE NUMBER\uFF1A+199999999\nWebsite URL\uFF1Ahttps://example.com/website/url\nZIP CODE\uFF1A000-0000\nADDRESS:San Francisco, CA 94107 United States\nNOTE\uFF1A\nHello, world!\nHello, ruby!\nHello, habakiri!\n"
result = Habakiri.exec(template, text)
pp result
# =>
# {"name"=>"John",
# "email"=>"[email protected]",
# "tel"=>"+199999999",
# "url"=>"https://example.com/website/url",
# "zipcode"=>"000-0000",
# "address"=>"San Francisco, CA 94107 United States",
# "note"=>"Hello, world!\n" + "Hello, ruby!\n" + "Hello, habakiri!"}
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/diaphragm/habakiri.
License
The gem is available as open source under the terms of the MIT License.