def setup(ruleset)
  ruleset.each_line.inject([]) do |rules, line|
    if line =~ /^\s*
      rules
    elsif line =~ /^(.+)\s+->\s+(\.?)(.*)$/
      rules << [$1, $3, $2!= ]
    else
      raise 
    end
  end
end

def morcov(ruleset, input_data)
  rules = setup(ruleset)
  while (matched = rules.find { |match, replace, term|
    input_data[match] and input_data.sub!(match, replace)
    }) and!matched[2]
  end
  input_data
end