Class: XDG::Paths::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/xdg/paths/directory.rb

Overview

A collection of XDG directories.

Constant Summary collapse

DELIMITER =
":"

Instance Method Summary collapse

Constructor Details

#initialize(pair, environment = ENV) ⇒ Directory

Returns a new instance of Directory.



9
10
11
12
13
# File 'lib/xdg/paths/directory.rb', line 9

def initialize pair, environment = ENV
  @pair = pair
  @environment = environment
  freeze
end

Instance Method Details

#defaultObject



15
# File 'lib/xdg/paths/directory.rb', line 15

def default = value.split(DELIMITER).map { |path| expand path }

#dynamicObject



17
18
19
20
21
22
# File 'lib/xdg/paths/directory.rb', line 17

def dynamic
  String(environment[key]).then { |env_value| env_value.empty? ? value : env_value }
                          .split(DELIMITER)
                          .uniq
                          .map { |path| expand path }
end

#inspectObject



28
29
30
31
32
33
# File 'lib/xdg/paths/directory.rb', line 28

def inspect
  pairs = to_s
  type = self.class

  pairs.empty? ? "#<#{type}:#{object_id}>" : "#<#{type}:#{object_id} #{self}>"
end

#to_sObject Also known as: to_str



24
# File 'lib/xdg/paths/directory.rb', line 24

def to_s = [key, dynamic.join(DELIMITER)].reject(&:empty?).join XDG::DELIMITER