Module: Contest::Driver::Utils

Defined in:
lib/contest/driver/common.rb

Class Method Summary collapse

Class Method Details

.normalize_language(label) ⇒ Object



44
45
46
47
48
49
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
77
78
79
80
81
82
83
84
85
# File 'lib/contest/driver/common.rb', line 44

def self.normalize_language label
  case label
  when "c", "C"
    return "clang"
  when "cpp", "C++", "c++", "cc", "cxx"
    return "cpp"
  when "c++11", "C++11"
    return "cpp11"
  when "cs", "c#", "C#"
    return "cs"
  when "d", "D", "dlang"
    return "dlang"
  when "go", "golang"
    return "golang"
  when "hs", "haskell", "Haskell"
    return "haskell"
  when "java", "Java"
    return "java"
  when "objc", "m"
    return "objc"
  when "ocaml", "ml", "OCaml"
    return "ocaml"
  when "Delphi", "delphi"
    return "delphi"
  when "pascal", "Pascal"
    return "pascal"
  when "perl", "Perl", "pl"
    return "perl"
  when "php", "PHP"
    return "php"
  when "python2"
    return "python2"
  when "python3", "python", "Python", "py"
    return "python3"
  when "ruby", "rb", "Ruby"
    return "ruby"
  when "scala", "Scala"
    return "scala"
  else
    abort "unknown language @ normalize language"
  end
end

.resolve_language(path) ⇒ Object



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

def self.resolve_language path
  # set first element if path is array
  if path.is_a? Array
    path = path[0]
  end
  regexp = /\.([a-z0-9]+)$/
  if path.match(regexp)
    return path.match(regexp)[1]
  else
    return nil
  end
end

.resolve_path(src) ⇒ Object

resolve wild card



21
22
23
24
25
26
27
28
29
# File 'lib/contest/driver/common.rb', line 21

def self.resolve_path src
  if src.match ','
    src.split(',').map do |path|
      resolve_wild_card(path)
    end
  else
    resolve_wild_card(src)
  end
end

.resolve_wild_card(path) ⇒ Object



16
17
18
# File 'lib/contest/driver/common.rb', line 16

def self.resolve_wild_card path
  `ls #{path} | cat | head -n 1`.strip
end