Project

roman

0.0
No release in over 3 years
Low commit activity in last 3 years
RomanNumeral class for working with roman numerals in a native form.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 1.8
>= 0.9
>= 13
>= 0.8
 Project Readme

Roman Numerals

Source Code | Report Issue

Gem Version Build Status

ABOUT

The Roman library provides a full-fledged Numeric subclass for working in Roman Numerals.

In most cases this library is probably overkill. Instead, Ruby Facets provides Roman numeral core extension methods for the Integer and String classes which are likely to do everything that one really needs. However, the RomanNumeral class has one advantage. It can be maniputated like any other Numeric object without having to switch back and forth between representations. Moreover, and probably most importantly, it makes an excellect example of how to create a Numeric subclass in Ruby.

HOW TO USE

We can create Roman numerals via the usual instantiation.

RomanNumeral.new(1)    #=> #<RomanNumeral:0x7f10e378ad48 @i=1>

But to make it easier the Integer class is extended with #to_roman.

1.to_roman             #=> #<RomanNumeral:0x7f10e378ad48 @i=1>

Roman numerals can also be formed from their String represnetation.

RomanNumeral.new('I')  #=> #<RomanNumeral:0x7f10e378ad48 @i=1>

'I'.to_roman           #=> #<RomanNumeral:0x7f10e378ad48 @i=1>

Because +RomanNumeral+ is a full-fledged subclass of Numeric, we can work with them like we can an Integer.

 a = 2.to_roman        #=> #<RomanNumeral:0x7f10e378ad48 @i=2>
 b = 3.to_roman        #=> #<RomanNumeral:0x7f10e378ad48 @i=3>
 r = a + b             #=> #<RomanNumeral:0x7f10e378ad48 @i=5>

When we want to see the actual Romanized figure, we simple call #to_s.

 r.to_s                #=> "IV"

HOW TO INSTALL

Using RubyGems:

gem install roman

COPYRIGHT & LICENSE

Copyright (c) 2007 Rubyworks

Roman is destributed under the terms of the BSD-2-Clause license.

Please see LICENSE.txt file for details.