lib/string/roman.rb in bblib-0.2.2 vs lib/string/roman.rb in bblib-0.3.0
- old
+ new
@@ -1,9 +1,9 @@
module BBLib
- # Converts any integer up to 1000 to a roman numeral string_a
+ # Converts any integer up to 1000 to a roman numeral
def self.to_roman num
return num.to_s if num > 1000
roman = {1000 => 'M', 900 => 'CM', 500 => 'D', 400 => 'CD', 100 => 'C', 90 => 'XC', 50 => 'L',
40 => 'XL', 10 => 'X', 9 => 'IX', 5 => 'V', 4 => 'IV', 3 => 'III', 2 => 'II', 1 => 'I'}
numeral = ""
@@ -16,28 +16,27 @@
numeral
end
def self.string_to_roman str
sp = str.split ' '
- sp.map! do |s|
+ sp.map do |s|
if s.drop_symbols.to_i.to_s == s.drop_symbols && !(s =~ /\d+\.\d+/)
- s.sub!(s.scan(/\d+/).first.to_s, BBLib.to_roman(s.to_i))
+ s = s.sub(s.scan(/\d+/).first.to_s, BBLib.to_roman(s.to_i))
else
s
end
- end
- sp.join ' '
+ end.join ' '
end
def self.from_roman str
sp = str.split(' ')
(0..1000).each do |n|
num = BBLib.to_roman n
if !sp.select{ |i| i[/#{num}/i]}.empty?
for i in 0..(sp.length-1)
if sp[i].drop_symbols.upcase == num
- sp[i].sub!(num ,n.to_s)
+ sp[i] = sp[i].sub(num ,n.to_s)
end
end
end
end
sp.join ' '