class Asciidoctor::Pdf::RomanNumeral
Constants
- BaseDigits
Public Class Methods
int_to_roman(value)
click to toggle source
# File lib/asciidoctor-pdf/roman_numeral.rb, line 82 def self.int_to_roman value result = '' BaseDigits.keys.reverse.each do |ival| while value >= ival value -= ival result += BaseDigits[ival] end end result end
new(initial_value, letter_case = nil)
click to toggle source
# File lib/asciidoctor-pdf/roman_numeral.rb, line 49 def initialize initial_value, letter_case = nil initial_value ||= 1 if initial_value.is_a? ::Integer @integer_value = initial_value else @integer_value = RomanNumeral.roman_to_int initial_value letter_case = :lower if letter_case.nil? && initial_value.upcase != initial_value end @letter_case = letter_case.nil? ? :upper : letter_case end
roman_to_int(value)
click to toggle source
# File lib/asciidoctor-pdf/roman_numeral.rb, line 93 def self.roman_to_int value value = value.upcase result = 0 BaseDigits.values.reverse.each do |rval| while value.start_with? rval offset = rval.length value = value[offset..offset] result += BaseDigits.key rval end end result end
Public Instance Methods
next()
click to toggle source
# File lib/asciidoctor-pdf/roman_numeral.rb, line 73 def next RomanNumeral.new @integer_value + 1, @letter_case end
next!()
click to toggle source
# File lib/asciidoctor-pdf/roman_numeral.rb, line 77 def next! @integer_value += 1 self end
to_i()
click to toggle source
# File lib/asciidoctor-pdf/roman_numeral.rb, line 69 def to_i @integer_value end
to_r()
click to toggle source
# File lib/asciidoctor-pdf/roman_numeral.rb, line 64 def to_r roman = RomanNumeral.int_to_roman @integer_value @letter_case == :lower ? roman.downcase : roman end
to_s()
click to toggle source
# File lib/asciidoctor-pdf/roman_numeral.rb, line 60 def to_s to_r end