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, line 49
def self.to_roman(int, num = '')
  NUMERAL.each { |key, val|
    until int < key; int -= key; num << val; end
  }

  COMPACT.each { |key, val| num.gsub!(key, val) }

  num
end

Public Instance Methods

to_roman → aString click to toggle source

Converts int to Roman numerals.

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