Class: SolvePb::Commandline

Inherits:
Object
  • Object
show all
Defined in:
lib/solve_pb/command_line.rb

Instance Method Summary collapse

Instance Method Details

#parseObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/solve_pb/command_line.rb', line 3

def parse
  args = [:url, :lang]
  @args = {}
  ARGV.each_with_index do |arg, index|
    @args[args[index]] = arg if index < 2
  end
  if @args[:lang].nil?
    puts "Using default language: Ruby"
    @args[:lang] = "ruby"
  end
  if @args[:url].nil?
    puts "Please specify at least the problem's URL. Example:"
    puts "$ SolvePb https://www.hackerrank.com/challenges/acm-icpc-team"
    return nil
  end
  if @args.size > 2
    puts "More than 2 parameters specified. Ignored last #{ARGV.size - 2} params."
  end
  unless supported_language? @args[:lang]
    puts "#{@args[:lang]} is not supported yet."
    return nil
  end
  return @args
end