Class: LCSC::LCSCResolver

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

Overview

LCSCResolver logic.

Instance Method Summary collapse

Constructor Details

#initialize(user, repository) ⇒ LCSCResolver

LCSCResolver 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.



12
13
14
15
# File 'lib/lcsc/resolver.rb', line 12

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

Instance Method Details

#resolveString?

Resolves the LCSC by creating an LCSPCache instance, locating the LCSCCounter file, requiring it, and then creating an LCSCCounter 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.



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

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

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

    exit(1)
  end

  require_relative(finder_path)

  count = ::LCSC::LCSCCounter.new(cache.path).count

  if count.nil?
    puts('Failed to count solutions. Please, check your input and try again.')

    exit(2)
  end

  count
end