Module: Nehm::PathManager

Defined in:
lib/nehm/path_manager.rb

Overview

Path manager works with download paths

Class Method Summary collapse

Class Method Details

.default_dl_pathObject



8
9
10
# File 'lib/nehm/path_manager.rb', line 8

def self.default_dl_path
  Cfg[:dl_path]
end

.get_path(path) ⇒ Object

Checks path for validation and returns it if valid



15
16
17
18
19
20
# File 'lib/nehm/path_manager.rb', line 15

def self.get_path(path)
  # Check path for existence
  UI.term 'Invalid download path. Please enter correct path' unless Dir.exist?(path)

  File.expand_path(path)
end

.set_dl_pathObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/nehm/path_manager.rb', line 22

def self.set_dl_path
  loop do
    ask_sentence = 'Enter path to desirable download directory'
    default_path = File.join(ENV['HOME'], '/Music')

    if Dir.exist?(default_path)
      ask_sentence << " (press Enter to set it to #{default_path.magenta})"
    else
      default_path = nil
    end

    path = UI.ask(ask_sentence + ':')

    # If user press enter, set path to default
    path = default_path if path == '' && default_path

    if Dir.exist?(path)
      Cfg[:dl_path] = File.expand_path(path)
      UI.say "#{'Download directory set up to'.green} #{path.magenta}"
      break
    else
      UI.error "This directory doesn't exist. Please enter correct path"
    end
  end
end