Class: AOJ::CLI
Defined Under Namespace
Modules: Helper
Instance Method Summary
collapse
Methods included from Helper
#conf, #detect_language, #detect_problem, #input_credentials, #print_result, #print_solution_info, #read_file, #twitter_auth
Instance Method Details
#langs ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/aoj/cli.rb', line 91
def langs
puts "List available languages:"
print " "
puts Language.languages.map(&:key).join(", ")
puts
puts "Auto-detect extensions:"
puts " " + "[ext]".ljust(10) + "[lang]"
Language.extnames.each do |k, v|
puts " " + k.ljust(10) + v.to_s
end
end
|
#omikuji ⇒ Object
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
|
# File 'lib/aoj/cli.rb', line 50
def omikuji
unless conf.has_credential?
input_credentials
puts
end
problem = AOJ::Problem.random_icpc(conf['username'])
title = "ID #{problem.id}"
width = title.size
line = "-" * (width + 4)
title_line = "| #{title} |"
lspace = " " * ((width + 1)/2)
rspace = " " * (width + 1 - (width + 1)/2)
body = [problem.name.split("")]
.transpose
.map { |s| "|#{lspace}#{s[0]}#{rspace}|" }
outer_width = problem.url.size
outer_lspace = " " * (outer_width/2 - line.size/2 - 2)
puts [line, title_line, line, body, line]
.flatten
.map { |s| outer_lspace + s }
.join("\n")
puts
puts problem.url
puts
rescue AOJ::Error::NoProblemLeftError
puts "No problem left. You are crazy!"
end
|
#setting ⇒ Object
81
82
83
|
# File 'lib/aoj/cli.rb', line 81
def setting
input_credentials
end
|
#submit(file) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/aoj/cli.rb', line 11
def submit(file)
unless conf.has_credential?
input_credentials
puts
end
solution = Solution.new.tap do |s|
s.source = read_file(file)
s.problem = detect_problem(file, options[:problem])
s.language = detect_language(file, options[:lang])
end
print_solution_info solution
puts
puts "Submitting..."
API.submit(solution, Credential.get)
puts
puts "Fetching judge result..."
result = API.judge_result(solution, Time.now, Credential.get)
puts
print_result result
if options[:twitter] and result.status == 'Accepted'
unless conf.
puts
end
.instance.post(solution, result)
end
rescue AOJ::Error::LanguageDetectionError,
AOJ::Error::APIError,
AOJ::Error::FetchResultError,
AOJ::Error::FileOpenError => e
puts e.message
end
|
86
87
88
|
# File 'lib/aoj/cli.rb', line 86
def
end
|