Class: Pdfrb::Layout::RomanNumeral

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/layout/list_box.rb

Overview

Roman numeral converter. Extracted as a standalone helper so ListBox and PageLabel (model layer) can share it.

Constant Summary collapse

MAPPINGS =
[[1000, "M"], [900, "CM"], [500, "D"], [400, "CD"],
[100, "C"], [90, "XC"], [50, "L"], [40, "XL"],
[10, "X"], [9, "IX"], [5, "V"], [4, "IV"], [1, "I"]].freeze

Class Method Summary collapse

Class Method Details

.convert(n) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pdfrb/layout/list_box.rb', line 12

def self.convert(n)
  return "0" if n <= 0

  result = +""
  MAPPINGS.each do |value, symbol|
    while n >= value
      result << symbol
      n -= value
    end
  end
  result
end