Can someone help me make this code not suck?
require 'test/unit'
# EWWWWWWW
def process_string str
result = Hash.new
str.to_a.each do |line|
line.scan(/important ([a-zA-Z0-9]+): /) do |key|
result[key.first] = line
end
end
result
end
class TestThis < Test::Unit::TestCase
def example_string
<<-END
# comments
important key1: some value's here
important key2: some value's here
important key3: some value's here
important key4: some value's here
other stuff we don't care about
END
end
def test_process_string
result = process_string example_string
assert 4, result.size
assert result.has_key?("key1")
assert result.has_key?("key2")
assert result.has_key?("key3")
assert result.has_key?("key4")
end
end