在文件夹中搜索.yml文件

时间:2017-12-07 16:42:17

标签: ruby yaml

我开发了一个系统,特定用户可以在该系统中搜索特定文件。问题是这个文件在一个文件夹中,所以我很难编码它。

我的方法必须能够在文件名中找到我的关键字输入。

例如,如果我搜索Bob,我将获得文件名中包含Bob的所有文件

def search_user(search)


            keyword = File.readlines('test3.yml')  


            matches = keyword.select { |username| username[/#{search}/] } 


            if File.read("test3.yml").include?(search) 
                puts "_____________________________________________"            
                puts ("Search results for student: " + search + ":") #
          puts
                puts matches
                puts "_____________________________________________"
                else #If not it will give the user feedback that its not there
                puts "_____________________________________________"
          puts
                puts ("Sorry, we couldnt find #{search} in the system.") 
                puts "_____________________________________________"
            end
    end

0 个答案:

没有答案
相关问题