Module: AtCoderFriends::PathUtil

Overview

Common methods and behaviors for dealing with paths.

Constant Summary collapse

SMP_DIR =
'data'
CASES_DIR =
'cases'
TMP_DIR =
'.tmp'

Class Method Summary collapse

Class Method Details

.cases_dir(dir) ⇒ Object



28
29
30
# File 'lib/at_coder_friends/path_util.rb', line 28

def cases_dir(dir)
  File.join(dir, CASES_DIR)
end

.contest_name(path) ⇒ Object



12
13
14
15
# File 'lib/at_coder_friends/path_util.rb', line 12

def contest_name(path)
  dir = File.file?(path) ? File.dirname(path) : path
  File.basename(dir).delete('#').downcase
end

.makedirs_unless(dir) ⇒ Object



37
38
39
# File 'lib/at_coder_friends/path_util.rb', line 37

def makedirs_unless(dir)
  FileUtils.makedirs(dir) unless Dir.exist?(dir)
end

.smp_dir(dir) ⇒ Object



24
25
26
# File 'lib/at_coder_friends/path_util.rb', line 24

def smp_dir(dir)
  File.join(dir, SMP_DIR)
end

.split_prg_path(path) ⇒ Object



17
18
19
20
21
22
# File 'lib/at_coder_friends/path_util.rb', line 17

def split_prg_path(path)
  dir, prg = File.split(path)
  base, ext = prg.split('.')
  q = base.split('_')[0]
  [path, dir, prg, base, ext, q]
end

.tmp_dir(path) ⇒ Object



32
33
34
35
# File 'lib/at_coder_friends/path_util.rb', line 32

def tmp_dir(path)
  dir = File.dirname(path)
  File.join(dir, '.tmp')
end