<commit_before>module XDG

  # Base Directory Standard
  class BaseDir

    # Try to get information from Ruby's install configuration.
    require 'rbconfig'

    sysconfdir = ::Config::CONFIG['sysconfdir'] || '/etc'
    datadir    = ::Config::CONFIG['datadir']    || '/usr/share'

    # Standard defaults for locations.
    DEFAULTS = {
      'XDG_DATA_HOME'   => ['~/.local/share'],
      'XDG_DATA_DIRS'   => ['/usr/local/share', datadir],
      'XDG_CONFIG_HOME' => ['~/.config'],
      'XDG_CONFIG_DIRS' => [File.join(sysconfdir,'xdg'), sysconfdir],
      'XDG_CACHE_HOME'  => ['~/.cache'],
      'XDG_CACHE_DIRS'  => ['/tmp']
    }

    # BaseDir iterates over directory paths.
    include Enumerable

    # Shortcut for `BaseDir.new`.
    def self.[](*env)
      new(*env)
    end

    # Initialize new instance of BaseDir class.
    def initialize(*env)
      @environment_variables = []
      env.each do |v|
        v = v.to_s.upcase
        if v !~ /_/
          @environment_variables << 'XDG_' + v + '_HOME'
          @environment_variables << 'XDG_' + v + '_DIRS'
        else
          @environment_variables << 'XDG_' + v
        end
      end
    end

    # The environment variables being referenced.
    #
    # @return [Array] list of XDG environment variable names
    def environment_variables
      @environment_variables
    end

    # The environment setting, or it's equivalent when the BaseDir
    # is a combination of environment variables.
    #
    # @return [String] evnironment vsetting
    def environment
      environment_variables.map{ |v| ENV[v] }.join(':')
    end

    # This is same as #environment, but also includes default values.
    #
    # @return [String] envinronment value.
    def environment_with_defaults
      environment_variables.map{ |v| ENV[v] || DEFAULTS[v] }.join(':')
    end

    # Shortcut for #environment_with_defaults.
    alias :env, :environment_with_defaults

    # Returns a complete list of expanded directories.
    #
    # @return [Array<String>] expanded directory list
    def to_a
      environment_variables.map do |v|
        if paths = ENV[v]
          dirs = paths.split(/[:;]/)
        else
          dirs = DEFAULTS[v]
        end
        dirs.map{ |path| expand(path) }
      end.flatten
    end

    # BaseDir is essentially an array.
    alias_method :to_ary, :to_a

    # Number of directory paths.
    def size<commit_msg>fix bug in #env alias<commit_after>module XDG

  # Base Directory Standard
  class BaseDir

    # Try to get information from Ruby's install configuration.
    require 'rbconfig'

    sysconfdir = ::Config::CONFIG['sysconfdir'] || '/etc'
    datadir    = ::Config::CONFIG['datadir']    || '/usr/share'

    # Standard defaults for locations.
    DEFAULTS = {
      'XDG_DATA_HOME'   => ['~/.local/share'],
      'XDG_DATA_DIRS'   => ['/usr/local/share', datadir],
      'XDG_CONFIG_HOME' => ['~/.config'],
      'XDG_CONFIG_DIRS' => [File.join(sysconfdir,'xdg'), sysconfdir],
      'XDG_CACHE_HOME'  => ['~/.cache'],
      'XDG_CACHE_DIRS'  => ['/tmp']
    }

    # BaseDir iterates over directory paths.
    include Enumerable

    # Shortcut for `BaseDir.new`.
    def self.[](*env)
      new(*env)
    end

    # Initialize new instance of BaseDir class.
    def initialize(*env)
      @environment_variables = []
      env.each do |v|
        v = v.to_s.upcase
        if v !~ /_/
          @environment_variables << 'XDG_' + v + '_HOME'
          @environment_variables << 'XDG_' + v + '_DIRS'
        else
          @environment_variables << 'XDG_' + v
        end
      end
    end

    # The environment variables being referenced.
    #
    # @return [Array] list of XDG environment variable names
    def environment_variables
      @environment_variables
    end

    # The environment setting, or it's equivalent when the BaseDir
    # is a combination of environment variables.
    #
    # @return [String] evnironment vsetting
    def environment
      environment_variables.map{ |v| ENV[v] }.join(':')
    end

    # This is same as #environment, but also includes default values.
    #
    # @return [String] envinronment value.
    def environment_with_defaults
      environment_variables.map{ |v| ENV[v] || DEFAULTS[v] }.join(':')
    end

    # Shortcut for #environment_with_defaults.
    alias_method :env, :environment_with_defaults

    # Returns a complete list of expanded directories.
    #
    # @return [Array<String>] expanded directory list
    def to_a
      environment_variables.map do |v|
        if paths = ENV[v]
          dirs = paths.split(/[:;]/)
        else
          dirs = DEFAULTS[v]
        end
        dirs.map{ |path| expand(path) }
      end.flatten
    end

    # BaseDir is essentially an array.
    alias_method :to_ary, :to_a

    # Number of directory paths.
    def size
{'fraction_non_alphanumeric': 0.11685625646328852, 'fraction_numerical': 0.0, 'mean_word_length': 2.43222143364088, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6394982', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1495, 'n_words': 409}