class GreenDay::Cli

Public Instance Methods

login() click to toggle source
# File lib/green_day/cli.rb, line 14
def login
  print 'username:'
  username = $stdin.gets(chomp: true)
  print 'password:'
  password = $stdin.noecho { |stdin| stdin.gets(chomp: true) }.tap { puts }

  AtcoderClient.new.login(username, password)
  puts(
    "Successfully created #{AtcoderClient::COOKIE_FILE_NAME}"
    .colorize(:green)
  )
end
new(contest_name) click to toggle source
# File lib/green_day/cli.rb, line 28
def new(contest_name)
  contest = Contest.new(contest_name, AtcoderClient.new)
  FileUtils.makedirs("#{contest.name}/spec")

  Parallel.each(contest.tasks) do |task|
    create_submit_file(task)
    create_spec_file(task)
  end

  puts "Successfully created #{contest.name} directory".colorize(:green)
end

Private Instance Methods

create_spec_file(task) click to toggle source
# File lib/green_day/cli.rb, line 46
def create_spec_file(task)
  test =
    TestBuilder.build_test(
      submit_file_path(task),
      task.sample_answers
    )
  File.open(spec_file_path(task), 'w') do |f|
    f.write(test)
  end
end
create_submit_file(task) click to toggle source
# File lib/green_day/cli.rb, line 42
def create_submit_file(task)
  File.open(submit_file_path(task), 'w')
end
spec_file_path(task) click to toggle source
# File lib/green_day/cli.rb, line 61
def spec_file_path(task)
  "#{task.contest.name}/spec/#{task.code}_spec.rb"
end
submit_file_path(task) click to toggle source
# File lib/green_day/cli.rb, line 57
def submit_file_path(task)
  "#{task.contest.name}/#{task.code}.rb"
end