Coder Social home page Coder Social logo

numbers_in_words's Introduction

Build Status Maintainability Test Coverage Gem Version License

Installation

gem 'numbers_in_words'

Usage

require 'numbers_in_words'

NumbersInWords.in_words(112)
#=> one hundred and twelve

NumbersInWords.in_numbers("one googol")
#=>10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

NumbersInWords.in_numbers("Seventy million, five-hundred and fifty six thousand point eight nine three")
#=> 70556000.893

NumbersInWords.in_numbers("nineteen sixty five")
#=> 1965

Monkey patch version

require 'numbers_in_words'
require 'numbers_in_words/duck_punch'
112.in_words
#=> one hundred and twelve

"one googol".in_numbers
#=>10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

"Seventy million, five-hundred and fifty six thousand point eight nine three".in_numbers
#=> 70556000.893

numbers_in_words's People

Contributors

dependabot[bot] avatar dimidd avatar jro31 avatar markborkum avatar markburns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

numbers_in_words's Issues

Please add CHANGELOG.md

@markburns thank you for open sourcing this cool gem!

Do you think it would be possible to maintain a changelog? I saw the version got recently bumped to 1.0 but I couldn't find out why - this is often when incompatible changes are made (I assume support for older ruby versions might have been dropped?)

This might help https://keepachangelog.com/en/1.0.0

Thanks again and merry Christmas!

Converting text with numbers and words

When converting a string 10 Million to numbers the output is 1000000 instead of outputting 10000000.

'10 Million'.in_numbers
=> 1000000

Similarly if no number words are within the string the result is 0 instead of being 100.

'100'.in_numbers
=> 0

I'm not sure if this is the desired behavior but it would be nice if it could handle these type of scenarios.

Maintain a changelog

Hi @markburns

Thanks so much for creating and maintaining this gem. I recently started using it and seems to work great for what I need.

Would it be possible to maintain a changelog? I just noticed the version got bumped to 1.x ๐ŸŽ‰ congrats! Are there any breaking changes? Looking at the commit history there might be some change surrounding older ruby versions and possibly some big fixes?

Thanks again for your work,
Axel

Unsupported conditions for numberinwords

Sorry, I'm not sure what the correct terminology to explain the issue below but it is likely something the library can improve upon

NumbersInWords.in_numbers("half a million dollars")
=> 1000000
NumbersInWords.in_numbers("a quarter million dollars")
=> 1000000

Big big problem in powers_of_ten.rb

POWERS_RX = Regexp.union(POWERS_OF_TEN.values[1..]).freeze

Fails because of a syntax error.

[1..] should be [1..x] where x is some integer.

We can't see how you could even run your tests with this in place because ours fail with the syntax error. We've switched back to 0.4.0

support short names

I think that it will be awesome to support short names as M, kk, MM for million.
What do you think?

SyntaxError in range

Hello

When I used ruby 2.4.0, I started getting errors:

/home/deploy/.rvm/gems/ruby-2.4.0/gems/numbers_in_words-0.5.1/lib/numbers_in_words/to_word.rb:4:in `require_relative': /home/deploy/.rvm/gems/ruby-2.4.0/gems/numbers_in_words-0.5.1/lib/numbers_in_words/number_group.rb:48: syntax error, unexpected ']' (SyntaxError)
to_s[(1 - LENGTH_OF_GOOGOL)..].to_i
                              ^

also

/home/deploy/.rvm/gems/ruby-2.4.0/gems/numbers_in_words-0.5.1/lib/numbers_in_words/parsing/number_parser.rb:4:in `require_relative': /home/deploy/.rvm/gems/ruby-2.4.0/gems/numbers_in_words-0.5.1/lib/numbers_in_words/parsing/parse_fractions.rb:30: syntax error, unexpected ']' (SyntaxError)
     nums[index_of_fraction..]
                              ^

however, I got not issue with ruby 2.3.0

Unexpected number parsing

Hi!

First of all thanks for this cool gem. I needed exactly this, something that can parse a numeric code - how a human would say it - to a number.

I did notice some quirks of the number parsing in my application:

2.7.4 :001 > NumbersInWords.in_numbers 'one two three four'
 => 1234 
2.7.4 :002 > NumbersInWords.in_numbers 'one two three four.'
 => 1234 
2.7.4 :003 > NumbersInWords.in_numbers '1234.'
 => 12034 
2.7.4 :004 > NumbersInWords.in_numbers '1234'
 => 1234.0

Maybe it's not designed to also recognize numeric values input, but as I'm using it in combination with speech recognition that's sometimes what I get.

For now I'm simply checking this myself and not pass these values into NumbersInWords:

  def parse_numeric_value(param)
    return if param.nil?

    cleansed_params = param.strip.chomp('.')
    if /^\d+$/.match? cleansed_params
      cleansed_params
    elsif cleansed_params
      NumbersInWords.in_numbers(cleansed_params).to_s
    end
  end

Incorrect return

Was just running some tests, and almost all returned correctly. I got the following return though:

[1] pry(main)> NumbersInWords.in_numbers('a thousand six hundred and fifty-five') => 1161

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.