Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/caruby/active_support/core_ext/string.rb,
lib/caruby/helpers/roman.rb,
lib/caruby/helpers/version.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#to_arabic ⇒ Integer
The integer equivalent of this roman numeral.
-
#to_version ⇒ Object
Returns this String as a Version.
Methods included from ActiveSupport::CoreExtensions::String::Inflections
#camelize, #classify, #constantize, #dasherize, #demodulize, #foreign_key, #humanize, #parameterize, #pluralize, #singularize, #tableize, #titleize, #underscore
Instance Method Details
#to_arabic ⇒ Integer
Returns the integer equivalent of this roman numeral.
4 5 6 7 8 9 10 11 |
# File 'lib/caruby/helpers/roman.rb', line 4 def to_arabic case self when /^(I{0,3})$/ then $1.size when /^(I{0,3})(V|X)$/ then ROMAN_UNITS[$2] - $1.size when /^(V)(I{0,3})$/ then ROMAN_UNITS[$1] + $2.size else raise ArgumentError.new("#{self} is not a roman numeral in the range I-X") end end |