Class: Sortme::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/sortme/path.rb

Class Method Summary collapse

Class Method Details

.customObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sortme/path.rb', line 31

def self.custom
  puts "Enter video path"
  video_path = gets.chomp

  puts "Enter music path"
  music_path = gets.chomp

  puts "Enter picture path"
  picture_path = gets.chomp

  save video_path, music_path, picture_path
end

.default_macObject



51
52
53
54
55
56
57
# File 'lib/sortme/path.rb', line 51

def self.default_mac
  picture_path = "#{@@mac_home}/Pictures"
  video_path = "#{@@mac_home}/Movies"
  music_path = "#{@@mac_home}/Music"

  save video_path, music_path, picture_path
end

.default_windowsObject



66
67
68
69
70
71
72
# File 'lib/sortme/path.rb', line 66

def self.default_windows
  picture_path =
  video_path =
  music_path =

  save video_path, music_path, picture_path
end

.getObject



44
45
46
47
48
49
# File 'lib/sortme/path.rb', line 44

def self.get
  home = File.expand_path("~")
  settings = "#{home}/sortme_settings.json"
  json = File.read(settings)
  JSON.parse(json)
end

.mac?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/sortme/path.rb', line 23

def self.mac?
  /darwin/ =~ RUBY_PLATFORM
end

.save(video_path, music_path, picture_path) ⇒ Object



59
60
61
62
63
64
# File 'lib/sortme/path.rb', line 59

def self.save(video_path, music_path, picture_path)
  home = File.expand_path("~")

  system "echo '{\"video\":\"#{video_path}\",\"picture\":\"#{picture_path}\"
  ,\"music\":\"#{music_path}\"}' > #{home}/sortme_settings.json"
end

.setObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sortme/path.rb', line 5

def self.set
  puts "Do you want to use default paths? (type y if you are unsure) (y/n) "
  choice = gets.chomp.downcase

  @@mac_home = home = File.expand_path("~")
  if choice=="y" && mac?
    default_mac
  elsif choice=="y" && windows?
    default_windows
  elsif choice=="custom"
    custom
  else
    p "oops! run again"
    exit
  end

end

.windows?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/sortme/path.rb', line 27

def self.windows?
  /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
end