class BigBrother::Counter
Constants
- IGNORED_COMMANDS
Public Class Methods
count_commands(lines)
click to toggle source
# File lib/big_brother/counter.rb, line 11 def self.count_commands(lines) commands = normalize_commands(lines) commands = reject_ignored_commands(commands) commands.each_with_object({}) do |(command, argument), count_hash| count_hash[command] ||= {} count_hash[command][argument] ||= 0 count_hash[command][argument] += 1 end end
count_commands_json(file = BigBrother::Settings.get("history_file"), api_key = nil)
click to toggle source
# File lib/big_brother/counter.rb, line 6 def self.count_commands_json(file = BigBrother::Settings.get("history_file"), api_key = nil) lines = BigBrother::Reader.lines_from_history_file(file) { api_key: api_key || BigBrother::Settings.get("api_key"), commands: count_commands(lines) }.to_json end
normalize_commands(commands)
click to toggle source
# File lib/big_brother/counter.rb, line 21 def self.normalize_commands(commands) commands.map do |command| normalize_single_command command end end
normalize_single_command(command)
click to toggle source
# File lib/big_brother/counter.rb, line 33 def self.normalize_single_command(command) command, argument = reject_flags(command)[0..1] [command, argument || ""] end
reject_flags(command)
click to toggle source
# File lib/big_brother/counter.rb, line 38 def self.reject_flags(command) command.split(" ").reject { |word| word[0] == "-" } end
reject_ignored_commands(commands)
click to toggle source
# File lib/big_brother/counter.rb, line 27 def self.reject_ignored_commands(commands) commands.reject do |cmd, _arg| IGNORED_COMMANDS.include? cmd.downcase end end