Class: Codeforces::Viewer::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/codeforces/viewer/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



10
11
12
13
14
15
16
17
18
# File 'lib/codeforces/viewer/application.rb', line 10

def initialize
  @option = {
    :contest_id  => nil,
    :problem_id  => nil,
    :input_only  => false,
    :output_only => false,
    :cache       => true,
  }
end

Instance Attribute Details

#optionObject

Returns the value of attribute option.



8
9
10
# File 'lib/codeforces/viewer/application.rb', line 8

def option
  @option
end

Instance Method Details

#parse_options(argv) ⇒ Object



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
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/codeforces/viewer/application.rb', line 20

def parse_options(argv)
  OptionParser.new do |option_parser|
    option_parser.banner = "Usage: codeforces_viewer -c {contest-id} -p {problem-id} [options]"
    option_parser.separator ""
    option_parser.version = Codeforces::Viewer::VERSION

    # contest id
    option_parser.on('-c contest-id', '--contest-id contest-id', 'specify codeforces contest id (e.g. 100, 99)', String) {|contest_id| @option[:contest_id] = contest_id }

    # problem_id
    option_parser.on('-p problem-id', '--problem-id problem-id', 'specify codeforces problem id (e.g. A, B)', String) {|problem_id| @option[:problem_id] = problem_id }
    
    option_parser.separator ""

    # show input only
    option_parser.on('-i input-no', '--input input-no', 'specify sample input id (0 is all)', Integer) {|flag| @option[:input_only] = flag }
    
    # show output only
    option_parser.on('-o input-no', '--output input-no', 'specify sample output id (0 is all)', Integer) {|flag| @option[:output_only] = flag }
    
    option_parser.separator ""

    # no cache
    option_parser.on('--no-cache', 'no cache html files') {|flag| @option[:cache] = flag }

    option_parser.separator ""

    # parse
    option_parser.parse! argv
  end

  # check
  if @option[:contest_id].nil? || @option[:contest_id] == ""
    abort "Error: contest id must be specified"
  end
  if @option[:problem_id].nil? || @option[:problem_id] == ""
    abort "Error: problem id must be specified"
  end
end

#showObject



60
61
62
63
# File 'lib/codeforces/viewer/application.rb', line 60

def show
  viewer = Codeforces::Viewer::Viewer.new @option
  viewer.show
end