Class: Agen::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/agen/finder.rb

Constant Summary collapse

LIMIT =
5
MIN_CHARS =
6

Instance Method Summary collapse

Constructor Details

#initialize(histfile, config_file = Runner::CONFIG_FILE) ⇒ Finder

Returns a new instance of Finder.



8
9
10
11
# File 'lib/agen/finder.rb', line 8

def initialize(histfile, config_file = Runner::CONFIG_FILE)
  @histfile = histfile
  @config_file = config_file
end

Instance Method Details

#commands(limit: LIMIT, min_chars: MIN_CHARS) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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