Sha256: 714ace033b37a3c62ca760497867ea09d2e59477a6c482ab1371d712048ca08c
Contents?: true
Size: 870 Bytes
Versions: 3
Compression:
Stored size: 870 Bytes
Contents
module Jekyll module Roman class Integer def initialize(number) @number = number.to_i end def to_roman roman_arr = { 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" } num = @number roman_arr.reduce("") do |res, (arab, roman)| whole_part, num = num.divmod(arab) res << roman * whole_part end end end def roman(input) if /\A\d+\z/.match(input.to_s) # input is a positive number Integer.new(input).to_roman else return input end end end end Liquid::Template.register_filter(Jekyll::Roman)
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
jekyll-roman-0.0.3 | lib/jekyll/roman.rb |
jekyll-roman-0.0.2 | lib/jekyll/roman.rb |
jekyll-roman-0.0.1 | lib/jekyll-roman.rb |