Takes your numbers and makes them *fancy*.
Converts numbers to strings.
2.humanize # => "two"
4.humanize # => "four"
8.humanize # => "eight"
15.humanize # => "fifteen"
16.humanize # => "sixteen"
23.humanize # => "twenty three"
42.humanize # => "forty two"All the way up to 156 digit numbers:
…If you are dealing with numbers larger than 156 digits, we accept patches. Word list is sourced from: [ Wordlist.source ]
Note: this extends to Ruby core classes Integer, Float, and BigDecimal.
See below for usage without extending Ruby core.
gem install humanizeor:
gem 'humanize'require 'humanize'100.humanize => "one hundred"
1001.humanize => "one thousand and one"
0.001.humanize => "zero point zero zero one"Note: this usage does not extend Ruby core.
Instead it relies on explicitly calling the pure function Humanize.format.
gem install humanizeor:
gem 'humanize', require: falserequire 'humanize/module' # does not extend Ruby corexHumanize.format(100) => "one hundred"
Humanize.format(1001) => "one thousand and one"
Humanize.format(0.001) => "zero point zero zero one"Humanize.configure do |config|
config.locale = :en # [:en, :es, :fr, :'fr-CH', :tr, :az, :de, :id, :th, :ru, :pt, :ms, :jp, :vi, :'zh-tw', :ar], default: :en
config.decimals_as = :digits # [:digits, :number], default: :digits
endThe default locale can be overridden by passing an explicit locale::
42.humanize(locale: :fr) # => "quarante-deux"
1666.humanize(locale: :tr) # => "bin altı yüz altmış altı"Or, functionally:
Humanize.format(42, locale: :fr) # => "quarante-deux"
Humanize.format(1666, locale: :tr) # => "bin altı yüz altmış altı"Similarly, the default display of decimals can be overridden by passing an explicit decimals_as: value:
0.42.humanize(decimals_as: :digits) # => "zero point four two"
0.42.humanize(decimals_as: :number) # => "zero point forty-two"Or, functionally:
Humanize.format(0.42, decimals_as: :digits) # => "zero point four two"
Humanize.format(0.42, decimals_as: :number) # => "zero point forty-two"Currently supported locales:
:en:es:fr:'fr-CH':tr:az:de:id:th:ru (except for decimals):pt:ms:jp:vi:zh-tw:arInstall development dependencies by running bundle install.
You can run mutation testing by calling bin/run_mutant.
No open issues yet, or sync has not completed.