module Nuggets::Integer::RomanMixin

Constants

COMPACT
NUMERAL

Public Class Methods

to_roman(int) → aString click to toggle source

Converts positive integer int to Roman numerals.

   # File lib/nuggets/integer/roman_mixin.rb
49 def self.to_roman(int, num = '')
50   NUMERAL.each { |key, val|
51     until int < key; int -= key; num << val; end
52   }
53 
54   COMPACT.each { |key, val| num.gsub!(key, val) }
55 
56   num
57 end

Public Instance Methods

to_roman → aString click to toggle source

Converts int to Roman numerals.

   # File lib/nuggets/integer/roman_mixin.rb
63 def to_roman
64   self == 0 ? 'N' : self < 0 ?
65     RomanMixin.to_roman(-self, '-') : RomanMixin.to_roman(self)
66 end