<commit_before>module Hooray
  # App settings
  class Settings
    CONFIG_DIR = ENV['HOME'] + '/.hooray/'

    class << self
      attr_accessor :all, :services, :devices, :macs

      def no_config_folder
        puts "No config folder, run `#{$PROGRAM_NAME} init`"
        puts
        exit 1
      end

      def load!
        no_config_folder unless Dir.exist?(CONFIG_DIR)
        @all = YAML.load_file(CONFIG_DIR + 'settings.yml')
        @services = YAML.load_file(CONFIG_DIR + 'services.yml')
        @devices  = YAML.load_file(CONFIG_DIR + 'devices.yml')
        @macs = {}
        File.read(CONFIG_DIR + 'nmap-mac-prefixes').each_line do |line|
          next if line =~ /^\s*#/
          prefix, *name = *line.split(/\s/)
          @macs.store(prefix, name.join(' '))
        end
      end

      def list
        out = 'SCAN: '
        out += ' SYN' if syn_scan
        out += ' SERVICE' if service_scan
        out += ' OS' if os_fingerprint
        out
      end

      def device(mac)
        devices[mac.to_sym] || devices[mac.to_s]
      end

      def family(mac)
        prefix = mac.to_s.gsub(':', '')[0,6].upcase
        macs[prefix]
      end

      def all
        @all ||= {}
      end

      def method_missing(meth, *params)
        if meth =~ /=/
          all[meth.to_s.gsub('=', '')] = params.first
        else
          arg = meth.to_s.gsub('?', '')
          all[arg] || all[arg.to_sym]
        end
      end<commit_msg>fix "[] for false" on Settings.device<commit_after>module Hooray
  # App settings
  class Settings
    CONFIG_DIR = ENV['HOME'] + '/.hooray/'

    class << self
      attr_accessor :all, :services, :devices, :macs

      def no_config_folder
        puts "No config folder, run `#{$PROGRAM_NAME} init`"
        puts
        exit 1
      end

      def load!
        no_config_folder unless Dir.exist?(CONFIG_DIR)
        @all = YAML.load_file(CONFIG_DIR + 'settings.yml')
        @services = YAML.load_file(CONFIG_DIR + 'services.yml')
        @devices  = YAML.load_file(CONFIG_DIR + 'devices.yml')
        @macs = {}
        File.read(CONFIG_DIR + 'nmap-mac-prefixes').each_line do |line|
          next if line =~ /^\s*#/
          prefix, *name = *line.split(/\s/)
          @macs.store(prefix, name.join(' '))
        end
      end

      def list
        out = 'SCAN: '
        out += ' SYN' if syn_scan
        out += ' SERVICE' if service_scan
        out += ' OS' if os_fingerprint
        out
      end

      def device(mac)
        devices ||= {}
        devices[mac.to_sym] || devices[mac.to_s]
      end

      def family(mac)
        prefix = mac.to_s.gsub(':', '')[0,6].upcase
        macs[prefix]
      end

      def all
        @all ||= {}
      end

      def method_missing(meth, *params)
        if meth =~ /=/
          all[meth.to_s.gsub('=', '')] = params.first
        else
          arg = meth.to_s.gsub('?', '')
          all[arg] || all[arg.to_sym]
        end
      end
{'fraction_non_alphanumeric': 0.13903017972193965, 'fraction_numerical': 0.002034587995930824, 'mean_word_length': 1.7673545966228894, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1035066', 'n_tokens_mistral': 1028, 'n_tokens_neox': 993, 'n_words': 218}