• Stars
    star
    466
  • Rank 94,105 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Takes your numbers and makes them *fancy*.

Humanize

Build Status

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:

999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999.humanize
# => "nine hundred and ninety nine quinquagintillion, nine hundred and ninety nine novenquadragintillion, nine hundred and ninety nine octoquadragintillion, nine hundred and ninety nine septenquadragintillion, nine hundred and ninety nine sesquadragintillion, nine hundred and ninety nine quinquadragintillion, nine hundred and ninety nine quattuorquadragintillion, nine hundred and ninety nine trequadragintillion, nine hundred and ninety nine duoquadragintillion, nine hundred and ninety nine unquadragintillion, nine hundred and ninety nine quadragintillion, nine hundred and ninety nine novemtrigintillion, nine hundred and ninety nine octotrigintillion, nine hundred and ninety nine septentrigintillion, nine hundred and ninety nine sextrigintillion, nine hundred and ninety nine quintrigintillion, nine hundred and ninety nine quattuortrigintillion, nine hundred and ninety nine trestrigintillion, nine hundred and ninety nine duotrigintillion, nine hundred and ninety nine untrigintillion, nine hundred and ninety nine trigintillion, nine hundred and ninety nine novemvigintillion, nine hundred and ninety nine octovigintillion, nine hundred and ninety nine septenvigintillion, nine hundred and ninety nine sexvigintillion, nine hundred and ninety nine quinvigintillion, nine hundred and ninety nine quattuortillion, nine hundred and ninety nine trevigintillion, nine hundred and ninety nine duovigintillion, nine hundred and ninety nine unvigintillion, nine hundred and ninety nine vigintillion, nine hundred and ninety nine novemdecillion, nine hundred and ninety nine octodecillion, nine hundred and ninety nine septendecillion, nine hundred and ninety nine sexdecillion, nine hundred and ninety nine quindecillion, nine hundred and ninety nine quattuordecillion, nine hundred and ninety nine tredecillion, nine hundred and ninety nine duodecillion, nine hundred and ninety nine undecillion, nine hundred and ninety nine decillion, nine hundred and ninety nine nonillion, nine hundred and ninety nine octillion, nine hundred and ninety nine septillion, nine hundred and ninety nine sextillion, nine hundred and ninety nine quintrillion, nine hundred and ninety nine quadrillion, nine hundred and ninety nine trillion, nine hundred and ninety nine billion, nine hundred and ninety nine million, nine hundred and ninety nine thousand nine hundred and ninety nine"

If you are dealing with numbers larger than 156 digits, we accept patches. Word list is sourced from: [ Wordlist.source ]

Usage

Install the gem using RubyGems

gem install humanize

or:

Add it to your Gemfile

gem 'humanize'

Include it in your program

require 'humanize'

Call the method on the numbers

100.humanize => "one hundred"
1001.humanize => "one thousand and one"
0.001.humanize => "zero point zero zero one"

Configuration

Humanize.configure do |config|
  config.default_locale = :en  # [:en, :es, :fr, :tr, :de, :id], default: :en
  config.decimals_as = :digits # [:digits, :number], default: :digits
end

Default values can be overriden:

42.humanize(locale: :fr) # => "quarante-deux"
1666.humanize(locale: :tr) # => "bin altı yüz altmış altı"

Decimals

You can choose how you want to display decimals:

0.42.humanize(decimals_as: :digits) # => "zero point four two"
0.42.humanize(decimals_as: :number) # => "zero point fourty-two"

I18n

Currently supported locales:

  • English: :en
  • Spanish: :es
  • French: :fr
  • Turkish: :tr
  • Azerbaijani :az
  • German: :de
  • Indonesian: :id
  • Thai: :th
  • Russian: :ru (except for decimals)
  • Portuguese: :pt
  • Malaysia :ms
  • Japanese :jp
  • Vietnamese :vi

Testing

Install development dependencies by running bundle install.

You can run mutation testing by calling bin/run_mutant.

Credits

  • Original idea: Brenton Fletcher
  • Unbastardisation of original idea: Ryan Bigg
  • Awesome speed up: Jack "Chendo" Chen

More Repositories

1

guides

Guides for Ruby and Elixir and whatever else I feel like
Ruby
1,528
star
2

by_star

Lets you find ActiveRecord + Mongoid objects by year, month, fortnight, week and more!
Ruby
1,045
star
3

distance_of_time_in_words

Better distance of time in words for Rails
Ruby
521
star
4

rboard

A fully featured forum system compatible with Rails 2.3
Ruby
293
star
5

joyofelixir

A gentle introduction to the Elixir programming language
HTML
139
star
6

twist-v2

A book review tool for Leanpub's Markdown Book Format
Ruby
127
star
7

twist

Book review application for LeanPub's Markdown format
Ruby
103
star
8

elastic

A thin veneer over HTTPotion that talks to Elastic Search
Elixir
65
star
9

mtg

Magic: The Gathering, but in Ruby
Ruby
63
star
10

railsbot

The #rubyonrails channel bot
PLSQL
47
star
11

summer

A Tiny IRC Bot framework
Ruby
43
star
12

houser

Lightweight multitenancy gem for Rails 3 and Rails 4
Ruby
32
star
13

chronic

Elixir
30
star
14

saas_book_examples

Ruby
27
star
15

searcher

Fun experiment in parsing search query strings (like Pivotal Tracker does)
Ruby
25
star
16

forem.heroku.com

The application that contains the forem engine example
Ruby
22
star
17

lookup

Lookup for Ruby & Rails api in the terminal
Ruby
20
star
18

surveyor-2

Culture Amp Junior Engineering Program - 2018 Coding Test
Ruby
19
star
19

ryanbigg.com

Jekyll-powered version of ryanbigg.com
HTML
18
star
20

elixir-irc

Naive implementation of an IRC server in Elixir
Elixir
17
star
21

postbin

Postbin written in Sinatra
Ruby
16
star
22

ordinalize

Ordinalize your numbers (like humanize)
Ruby
15
star
23

chirper

Ruby
15
star
24

toy_robot_elixir

Code from leanpub.com/elixir-toyrobot
Elixir
13
star
25

writing-an-interpreter-in-elixir

Elixir
12
star
26

asciidoc-toolchain

Ruby
11
star
27

bix

Ruby
11
star
28

screencasts

Code for the screencasts I record
Ruby
10
star
29

forem-redcarpet

Provides Recarpet markup (with syntax highlighting by pygments.rb) for Forem posts}
Ruby
8
star
30

logs

JavaScript
7
star
31

maintaining-rails-examples

Ruby
6
star
32

exploding-rails-rom-dry-example-app

Ruby
6
star
33

setup

Go
6
star
34

exploding-rails-examples

Ruby
6
star
35

fans

Simple application showing how to do models for user's "favouriting" other users.
Ruby
5
star
36

graphql_book_examples

The code from the book "GraphQL for Rails Developers"
Ruby
5
star
37

jot

A light wrapper around the JWT gem
Ruby
5
star
38

banana

A warden example app
Ruby
4
star
39

find_by_hash

Extension to ActiveRecord to allow you to do findy-thingies with hashes
Ruby
4
star
40

logs.ex

Phoenix application for displaying IRC logs from some select channels
Elixir
4
star
41

numero

Numero language
Ruby
4
star
42

surveyor

Culture Amp's Junior Engineering Program - 2017 Coding Test
Ruby
4
star
43

phoenix-react-websocket-todo

Elixir
3
star
44

debugging_book_examples

Debugging Book Example Code
Ruby
3
star
45

phoenix-views-example

Elixir
3
star
46

cartify

REST / GraphQL demo
Ruby
3
star
47

rails-init

Go
3
star
48

wedding

App for managing wedding seating plan
Ruby
3
star
49

forem-rdiscount

RDiscount formatting support for Forem
Ruby
3
star
50

logs.ex-legacy

The old logs.ex.
JavaScript
3
star
51

promo

Toy project of building a promotion system in Elixir
Elixir
2
star
52

service-vic-qr-code

TypeScript
2
star
53

scrivener_elastic

Elixir
2
star
54

rubyonrailsbook.com

JavaScript
2
star
55

activitypub-spike

Ruby
2
star
56

epub_gen

A small RubyGem to generate epubs
Ruby
2
star
57

rails3book_test

Nothing to see here, move along.
2
star
58

just

For when you're just visiting (someone else's computer)
Ruby
2
star
59

logs-react

JavaScript
1
star
60

buildkite-notifier

Ruby
1
star
61

surveyor-rom

Ruby
1
star
62

http-test

Ruby
1
star
63

trickery

Ruby
1
star
64

yaml-path-finder

CSS
1
star
65

barefoot

JavaScript
1
star
66

webpacker-typescript-css-modules

Ruby
1
star
67

selector

Ruby
1
star
68

jep-mumble

Ruby
1
star
69

toy_robot_example

Ruby
1
star
70

jep-toy-robot

Elixir
1
star
71

rails-init-homebrew-tap

Ruby
1
star
72

sri

A tool to generate Sub-Resource Integrity hashes from the terminal
Ruby
1
star
73

auth_me

Ruby
1
star
74

webpack-example

Ruby
1
star