class Search::CLI
Attributes
glob[R]
limit[R]
search[R]
Public Class Methods
new(search, options)
click to toggle source
# File lib/search/cli.rb, line 5 def initialize(search, options) @search = search @glob = options[:files] @limit = options[:n] end
Public Instance Methods
filenames()
click to toggle source
# File lib/search/cli.rb, line 19 def filenames Dir.glob(glob) end
files()
click to toggle source
# File lib/search/cli.rb, line 11 def files raise Error, 'You must provide files to search' if glob.nil? filenames.map do |filename| File.open(filename) end end
qualities()
click to toggle source
# File lib/search/cli.rb, line 23 def qualities filenames_with_quality = files.map do |file| [Search.new(search, haystack: file.read).quality, file.path] end filenames_with_quality.sort_by(&:first).reverse[0, limit] end
suggestions()
click to toggle source
# File lib/search/cli.rb, line 31 def suggestions files.map do |file| Search.new(search, haystack: file.read).suggestions end[0, limit] end