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 85
def self.int_to_roman value
  result = []
  BaseDigits.keys.reverse_each do |ival|
    while value >= ival
      value -= ival
      result << BaseDigits[ival]
    end
  end
  result.join
end
new(initial_value, letter_case) click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 51
def initialize initial_value, letter_case
  @integer_value = ::Integer === initial_value ? initial_value : (RomanNumeral.roman_to_int initial_value)
  @letter_case = letter_case
end
roman_to_int(value) click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 96
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 68
def next
  RomanNumeral.new @integer_value + 1, @letter_case
end
next!() click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 72
def next!
  @integer_value += 1
  self
end
nil_or_empty?() click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 81
def nil_or_empty?
  false
end
pred() click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 77
def pred
  RomanNumeral.new @integer_value - 1, @letter_case
end
to_r() click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 60
def to_r
  if (int = @integer_value) < 1
    return int.to_s
  end
  roman = RomanNumeral.int_to_roman int
  @letter_case == :lower ? roman.downcase : roman
end
to_s() click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 56
def to_s
  to_r
end