stephencelis / scantron

Rule-based string scanning and scrubbing.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scantron

github.com/stephencelis/scantron

A simple, but powerful, rule-based string scanner and scrubber.

Examples

NumberScanner

require "scantron"
require "number_scanner"

NumberScanner.scan "A one, 2, 3.0, 4 1/2..."
# => [1, 2, 3.0, (9/2)]

number_scanner = NumberScanner.new <<HERE
  Ninety-nine bottles of beer on the wall.
  Ninety-nine bottles of beer.
  Take one down, pass it around,
  Ninety-eight and a half bottles of beer on the wall.
HERE

number_scanner.scan # => [99, 99, 1, (197/2)]

puts number_scanner.scrub { |n| "<span data-n='#{n.value.to_f}'>#{n}</span>" }
<span data-n='99.0'>Ninety-nine</span> bottles of beer on the wall.
<span data-n='99.0'>Ninety-nine</span> bottles of beer.
Take <span data-n='1.0'>one</span> down, pass it around,
<span data-n='98.5'>Ninety-eight and a half</span> bottles of beer on the wall.

RangeScanner

require "scantron"
require "range_scanner"

RangeScanner.scan "100-150 degrees"
# => [100..150]

RangeScanner.scan "Twelve or thirteen rolls for five or six people"
# => [12..13, 5..6]

Build Your Own

TODO

Install

% [sudo] gem install scantron

Or, with Bundler, add gem "scantron" to your Gemfile and run bundle install.

License

(The MIT License)

© 2010 Stephen Celis <stephen@stephencelis.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Rule-based string scanning and scrubbing.


Languages

Language:Ruby 100.0%