Class: AtCoderFriends::PathInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/at_coder_friends/path_info.rb

Overview

holds target path information

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PathInfo

Returns a new instance of PathInfo.



12
13
14
15
16
17
# File 'lib/at_coder_friends/path_info.rb', line 12

def initialize(path)
  @path = path
  # in setup command, path is directory name (existent/non-existent)
  # in other commands(test, submit, verify), path is existent file name
  @dir = File.file?(path) ? File.dirname(path) : path
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



10
11
12
# File 'lib/at_coder_friends/path_info.rb', line 10

def dir
  @dir
end

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/at_coder_friends/path_info.rb', line 10

def path
  @path
end

Instance Method Details

#cases_dirObject



39
40
41
# File 'lib/at_coder_friends/path_info.rb', line 39

def cases_dir
  File.join(dir, CASES_DIR)
end

#cases_out_dirObject



43
44
45
# File 'lib/at_coder_friends/path_info.rb', line 43

def cases_out_dir
  File.join(dir, TMP_DIR, CASES_DIR)
end

#componentsObject



23
24
25
26
27
28
29
# File 'lib/at_coder_friends/path_info.rb', line 23

def components
  # overwrites @dir here for non-existent files (test purpose)
  @dir, prg = File.split(path)
  base, ext = prg.split('.')
  q = base.gsub(/_[^#_]+\z/, '')
  [path, dir, prg, base, ext, q]
end

#contest_nameObject



19
20
21
# File 'lib/at_coder_friends/path_info.rb', line 19

def contest_name
  File.basename(dir).delete('#').downcase
end

#smp_dirObject



35
36
37
# File 'lib/at_coder_friends/path_info.rb', line 35

def smp_dir
  File.join(dir, SMP_DIR)
end

#src_dirObject



31
32
33
# File 'lib/at_coder_friends/path_info.rb', line 31

def src_dir
  dir
end

#tmp_dirObject



47
48
49
# File 'lib/at_coder_friends/path_info.rb', line 47

def tmp_dir
  File.join(dir, TMP_DIR)
end