class ChainedValidation::Rules::Roman

Public Class Methods

new(params) click to toggle source
# File lib/chained_validation/rules/roman.rb, line 4
def initialize(params)
  @object = params.fetch(:object)
end

Public Instance Methods

perform() click to toggle source
# File lib/chained_validation/rules/roman.rb, line 8
def perform
  ChainedValidation::Validation.new(roman: { object: @object, result: is_roman? })
end

Private Instance Methods

is_roman?() click to toggle source
# File lib/chained_validation/rules/roman.rb, line 14
def is_roman?
  # Based on Regular Expression Grabbag in the O'Reilly Perl Cookbook, #6.23
  regexp = /^M*(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$/i
  regexp === @object.to_s
end