Project

parsenum

0.0
No commit activity in last 3 years
No release in over 3 years
Simple parsing of numeric values from strings
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.6
>= 0
 Project Readme

Parsenum

Because sometimes you just want to get numbers out of strings damnit.

This acutally happens a surprising amount. Usually when reading a CSV or scraping a webpage you want extract a number out of a test string. Sure in the simple case .to_i and .to_f work fine but often there's pesky things like commas or pound signs getting in the way.

This library is pretty dumb as parsers go but it's just an attempt to hide all the string ugliness so you can get to the numbers you need.

Simple examples

"123".number                => 123
"1.23".number               => 1.23
"£3.99".number              => 3.99
"28.5%".number              => 0.285
"$1.99".number              => 1.99
"got 99 problems".number    => 99
"8 out of 10 cats".numbers  => [8, 10]

Advanced Examples

number = Parsenum.parse("$3.99")
number.value      => 3.99
number.currency?  => true
number.currency   => 'USD'

number = Parsenum.parse("68%")
number.value        => 0.68
number.percentage?  => true
numbers = Parsenum.parse_all("8 out of 10 cats")
numbers.size               => 2
numbers.first.value        => 8
numbers.first.integer?     => true

TODO

  • support for more currencies
  • bigdecimel support