Class: PathControl

Inherits:
Object
  • Object
show all
Defined in:
lib/nehm/path_control.rb

Class Method Summary collapse

Class Method Details

.dl_pathObject



2
3
4
# File 'lib/nehm/path_control.rb', line 2

def self.dl_path
  @temp_dl_path ? @temp_dl_path : Config[:dl_path]
end

.itunes_pathObject



41
42
43
# File 'lib/nehm/path_control.rb', line 41

def self.itunes_path
  Config[:itunes_path]
end

.itunes_path_nameObject

Use in Configure.menu



46
47
48
# File 'lib/nehm/path_control.rb', line 46

def self.itunes_path_name
  PathControl.itunes_path.sub("/iTunes\ Media/Automatically\ Add\ to\ iTunes.localized", '')
end

.set_dl_pathObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/nehm/path_control.rb', line 6

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

    if Dir.exist?(default_path)
      path_ask << " (press enter to set it to #{Paint[default_path, :magenta]})"
    else
      default_path = nil
    end

    path = HighLine.new.ask(path_ask + ':')
    path = default_path if path == '' && default_path

    path = PathControl.tilde_to_home(path) if PathControl.tilde_at_top?(path)

    if Dir.exist?(path)
      Config[:dl_path] = path
      puts Paint["Download directory set up to #{Paint[path, :magenta]}", :green]
      break
    else
      puts Paint["This directory doesn't exist. Please enter path again", :red]
    end
  end
end

.set_itunes_pathObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/nehm/path_control.rb', line 50

def self.set_itunes_path
  loop do
    default_path = File.join(ENV['HOME'], '/Music/iTunes')
    path_ask = 'Enter path to iTunes directory'

    if Dir.exist?(default_path)
      path_ask << " (press enter to set it to #{Paint[default_path, :magenta]})"
    else
      default_path = nil
    end

    path = HighLine.new.ask(path_ask + ':')
    path = default_path if path == '' && default_path

    path = PathControl.tilde_to_home(path) if PathControl.tilde_at_top?(path)

    path = File.join(path, "iTunes\ Media/Automatically\ Add\ to\ iTunes.localized")

    if Dir.exist?(path)
      Config[:itunes_path] = path
      puts Paint["iTunes directory set up to #{Paint[path, :magenta]}", :green]
      break
    else
      puts Paint["This directory doesn't exist. Please enter path again", :red]
    end
  end
end

.set_itunes_path_to_defaultObject



78
79
80
# File 'lib/nehm/path_control.rb', line 78

def self.set_itunes_path_to_default
  Config[:itunes_path] = File.join(ENV['HOME'], "/Music/iTunes/iTunes\ Media/Automatically\ Add\ to\ iTunes.localized")
end

.temp_dl_path=(path) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/nehm/path_control.rb', line 32

def self.temp_dl_path=(path)
  if Dir.exist?(path)
    @temp_dl_path = path
  else
    puts Paint['Invalid path!', :red]
    exit
  end
end

.tilde_at_top?(path) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/nehm/path_control.rb', line 86

def self.tilde_at_top?(path)
  path[0] == '~' ? true : false
end

.tilde_to_home(path) ⇒ Object



82
83
84
# File 'lib/nehm/path_control.rb', line 82

def self.tilde_to_home(path)
  File.join(ENV['HOME'], path[1..-1])
end