Class: String

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::CoreExtensions::String::Inflections
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

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_arabicInteger

Returns the integer equivalent of this roman numeral.

Returns:

  • (Integer)

    the integer equivalent of this roman numeral

Raises:

  • ArgumentError if this String is not a roman numeral in the range I-X



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

#to_versionObject

Returns this String as a Version.

Examples:

"1.2.1alpha".to_version #=> [1, 2, "1alpha"]


52
53
54
55
# File 'lib/caruby/helpers/version.rb', line 52

def to_version
  components = split('.').map { |component| component =~ /[\D]/ ? component : component.to_i }
  Version.new(*components)
end