https://github.com/rubyworks/roman
Roman Numeral Class
https://github.com/rubyworks/roman
Last synced: 11 months ago
JSON representation
Roman Numeral Class
- Host: GitHub
- URL: https://github.com/rubyworks/roman
- Owner: rubyworks
- License: other
- Created: 2011-12-06T23:09:06.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2013-03-09T14:37:12.000Z (almost 13 years ago)
- Last Synced: 2025-03-08T17:03:48.683Z (12 months ago)
- Language: Ruby
- Homepage:
- Size: 176 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Roman Numerals
[Website](http://rubyworks.github.com/roman) /
[Documentation](http://rubydoc.info/gems/roman/frames) /
[Report Issue](http://github.com/rubyworks/roman/issues) /
[Source Code](http://github.com/rubyworks/roman)
[](http://flattr.com/thing/324911/Rubyworks-Ruby-Development-Fund)
## STATUS
[](http://badge.fury.io/rb/roman)
[](https://travis-ci.org/rubyworks/roman)
## 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](http://rubyworks.github.com/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) #=> #
But to make it easier the Integer class is extended with #to_roman.
1.to_roman #=> #
Roman numerals can also be formed from their String represnetation.
RomanNumeral.new('I') #=> #
'I'.to_roman #=> #
Because +RomanNumeral+ is a full-fledged subclass of Numeric,
we can work with them like we can an Integer.
a = 2.to_roman #=> #
b = 3.to_roman #=> #
r = a + b #=> #
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](http://spdx.org/license/BSD-2-Clause) license.
Please see LICENSE.txt file for details.