class Agen::Finder
Constants
- LIMIT
- MIN_CHARS
Attributes
config_file[R]
Public Class Methods
new(histfile, config_file = Runner::CONFIG_FILE)
click to toggle source
# File lib/agen/finder.rb, line 8 def initialize(histfile, config_file = Runner::CONFIG_FILE) @histfile = histfile @config_file = config_file end
Public Instance Methods
commands(limit: LIMIT, min_chars: MIN_CHARS)
click to toggle source
# File lib/agen/finder.rb, line 13 def commands(limit: LIMIT, min_chars: MIN_CHARS) lines .each_with_object(Hash.new(0)) do |line, commands| cmd = line.split(";").last.delete("\n") commands[cmd] += 1 if cmd != "" rescue => e puts e end .sort_by { |k, v| -v } .to_h .keys .select { |cmd| cmd.length >= min_chars } .select { |cmd| !ignored?(cmd) } .first(limit) end
Private Instance Methods
ignored?(cmd)
click to toggle source
# File lib/agen/finder.rb, line 33 def ignored?(cmd) File.readlines(config_file).detect do |line| line.delete("\n") == cmd end rescue Errno::ENOENT # User hasn't ignored anything yet, so doesn't have a config file end
lines()
click to toggle source
# File lib/agen/finder.rb, line 41 def lines File.readlines(@histfile).reverse end