lib/cousin_roman/roman.rb in cousin_roman-1.0.7 vs lib/cousin_roman/roman.rb in cousin_roman-1.0.8
- old
+ new
@@ -19,12 +19,11 @@
def convert(number)
intermediate = number.dup.downcase
compound = braketize_value_of SUBTRACTIVES
singular = braketize_value_of ONES.merge(FIVES)
- compound.each { |literal, val| intermediate.gsub!(literal, val) }
- singular.each { |literal, val| intermediate.gsub!(literal, val) }
+ [compound, singular].each { |factors| factors.each { |literal, val| intermediate.gsub!(literal, val) } }
intermediate.scan(/\((\d*)\)/).reduce(0) do |sum, term|
sum + term.first.to_i
end
end
@@ -34,14 +33,11 @@
convert clean if valid? clean
end
def to_arabian!(number)
clean = number.strip
- if valid? clean
- convert clean
- else
- raise TypeError, 'not a valid roman number'
- end
+ valid? clean or raise TypeError, 'not a valid roman number'
+ convert clean
end
def roman_regex
/^(M{0,3})(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$/i
end