Module: Contest::Driver::Utils
- Defined in:
- lib/contest/driver/common.rb
Class Method Summary collapse
- .check_file_map(label, ext_map) ⇒ Object
-
.get_all_drivers ⇒ Object
find all driver.
- .get_file_ext(filename) ⇒ Object
-
.load_plugins ⇒ Object
Load Plugins.
- .normalize_language(label) ⇒ Object
- .resolve_file_map(label, ext_map) ⇒ Object
- .resolve_language(path) ⇒ Object
-
.resolve_path(src) ⇒ Object
resolve wild card.
- .resolve_wild_card(path) ⇒ Object
Class Method Details
.check_file_map(label, ext_map) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/contest/driver/common.rb', line 75 def self.check_file_map label, ext_map if ext_map.is_a? Hash ext = get_file_ext(label) ext_map.has_key?(ext) else false end end |
.get_all_drivers ⇒ Object
find all driver
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/contest/driver/common.rb', line 17 def self.get_all_drivers return [] unless defined? Contest::Driver Contest::Driver.constants.select {|class_name| /.*Driver$/ =~ class_name.to_s }.map {|driver_class_name| driver = Contest::Driver.const_get(driver_class_name).new { :class_name => driver_class_name, :site_info => { :name => driver.get_site_name(), :desc => driver.get_desc(), }, } } end |
.get_file_ext(filename) ⇒ Object
71 72 73 |
# File 'lib/contest/driver/common.rb', line 71 def self.get_file_ext filename File.extname(filename)[1..-1] end |
.load_plugins ⇒ Object
Load Plugins
36 37 38 39 40 41 |
# File 'lib/contest/driver/common.rb', line 36 def self.load_plugins # load drivers Dir.glob("#{$git_contest_home}/plugins/**") do |path| require path if /\/.*_driver\.rb$/.match path end end |
.normalize_language(label) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/contest/driver/common.rb', line 89 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 "javascript", "js" return "javascript" 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 "pl", "prolog" return "prolog" 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_file_map(label, ext_map) ⇒ Object
84 85 86 87 |
# File 'lib/contest/driver/common.rb', line 84 def self.resolve_file_map label, ext_map ext = get_file_ext(label) ext_map[ext] end |
.resolve_language(path) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/contest/driver/common.rb', line 58 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
48 49 50 51 52 53 54 55 56 |
# File 'lib/contest/driver/common.rb', line 48 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
43 44 45 |
# File 'lib/contest/driver/common.rb', line 43 def self.resolve_wild_card path `ls #{path} | cat | head -n 1`.strip end |