Skip to content

febonazzic/romanumerals

Repository files navigation

Romanumerals

RSpec codecov

This gem allows you to convert arabic numbers to roman.

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add romanumerals

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install romanumerals

Usage

Usage is very simple:

Convert to roman:

10.to_roman # => "X" 
110.to_roman # => "CX" 
99.to_roman # => "XCIX"
845.to_roman # => "DCCCXLV"
1193.to_roman # => "MCXCIII"
2024.to_roman # => "MMXXIV"

Convert from roman:

'MMXXIV'.to_numeral # => 2024

Other cases:

0.to_roman # => ""
11.9.to_roman # => "XI"

# If a string does not contain roman numerals then the String#to_i will be used 
''.to_numeral # => 0
'0'.to_numeral # => 0
'XIIi'.to_numeral # => 0
'5 contributors'.to_numeral # => 5

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/febonazzic/romanumerals.

License

The gem is available as open source under the terms of the MIT License.