numb

Returns any numbers, currency or percentages it can find.

Currencies are returned using the standard currency codes (see wikipedia for example) => 10.00, :percent => true, :currency => ‘EUR’ Note: Currently, ‘kr’ will return ‘DKK’ even though this is the currency symbol for

Sweden, Danmark and Norway. This issue exists for other currencies as well.

New Options:

:require => 
            :currency
            :value
            :percent

Throws an error if the required field isn’t there. Can be combined:

Numb.new(:require => [:currency, :value])

:split => ['<br/>', '//']

Splits the fields based on the passed variables in the order they are passed

:debug => true

Prints out debugging info.

Examples

Numb.new.parse(“US$1.00&nbsp;”) # => => ‘USD’, :value => 1.00

Numb.new.parse(‘12.34%’) # => => true, :value => 12.34

Supported Currencies

ALL AFN ARS AWG AUD AZN BSD BBD BYR BZD BMD BOB BAM BWP BGN BRL BND KHR CAD KYD CLP CNY COP CRC HRK CUP CZK DOP XCD EGP SVC EEK FKP FJD GHC GIP GTQ GGP GYD HNL HKD HUF ISK IDR IRR IMP ILS JMD JPY JEP KZT KPW KRW KGS LAK LVL LBP LRD CHF LTL MKD MYR MUR MXN MNT MZN NAD NPR ANG NZD NIO NGN KPW NOK OMR PKR PAB PYG PEN PHP PLN QAR RON RUB SHP SAR RSD SCR SBD SOS ZAR KRW LKR CHF SRD SYP TWD THB TTD TRY TRL TVD UAH UYU UZS VEF VND YER ZWD

Duplicate currencies which will not correctly identify

PRIMARY = { ‘£’ => ‘GBP’, ‘kr’ => ‘DKK’, ‘$’ => ‘USD’, ‘¥’ => ‘JPY’, ‘ƒ’ => ‘AWG’, }

DUPLICATES =

'£' => ['EGP', 'FKP', 'GIP', 'GGP', 'IMP', 'JEP', 'LBP', 'SHP', 'SYP', 'EEK'],
'kr' => ['ISK', 'NOK', 'SEK'],
'$' => ['ARS', 'AUD', 'BSD', 'BBD', 'BMD', 'BND', 'CAD', 'KYD', 'CLP', 'COP', 
        'FJD', 'GYD', 'HKD', 'LRD', 'MXN', 'NAD', 'NZD', 'SGD', 'SBD', 'SVC', 'TVD', 'SRD', 'XCD'],
'¥' => 'CNY',
'ƒ' => 'ANG',

Copyright © 2009 TrafficBroker Ltd. See LICENSE for details.