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 102 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 = nil)
click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 50 def initialize initial_value, letter_case = nil initial_value ||= 1 if ::Integer === initial_value @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 113 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
empty?()
click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 98 def empty? false end
even?()
click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 81 def even? to_i.even? end
next()
click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 85 def next RomanNumeral.new @integer_value + 1, @letter_case end
next!()
click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 89 def next! @integer_value += 1 self end
odd?()
click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 77 def odd? to_i.odd? end
pred()
click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 94 def pred RomanNumeral.new @integer_value - 1, @letter_case end
to_i()
click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 73 def to_i @integer_value end
to_r()
click to toggle source
# File lib/asciidoctor/pdf/roman_numeral.rb, line 65 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 61 def to_s to_r end