Class: LCSP::LCSPResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/lcsp/resolver.rb

Overview

LCSPResolver logic.

Instance Method Summary collapse

Constructor Details

#initialize(user, repository, number) ⇒ LCSPResolver

LCSPResolver is entry point for any LCSP request by user.

Parameters:

  • user (String)

    The GitHub username of the user.

  • repository (String)

    The name of the repository containing the LCSP problem.

  • number (Integer)

    The problem number for which the LCSP needs to be resolved.



13
14
15
16
17
# File 'lib/lcsp/resolver.rb', line 13

def initialize(user, repository, number)
  @user = user
  @repository = repository
  @number = number
end

Instance Method Details

#resolveString?

Resolves the LCSP by creating an LCSPCache instance, locating the LCSPFinder file, requiring it, and then creating an LCSPFinder instance to find the solution.

Returns:

  • (String)

    The solution to the LCSP problem.

  • (nil)

    If the LCSPFinder file is not found or the solution is not found.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/lcsp/resolver.rb', line 24

def resolve
  cache = ::LCSP::LCSPCache.new(@user, @repository)
  finder_path = "#{cache.path}/lcsp/finder.rb"

  unless ::File.exist?(finder_path)
    puts('finder.rb not found in repository. Please, check config and try again.')

    exit(1)
  end

  require_relative(finder_path)

  solution = ::LCSP::LCSPFinder.new(cache.path, @number).solution

  if solution.nil?
    puts('Solution not found. Please, check your input and try again.')

    exit(2)
  end

  solution
end