Test pushing on new laptop
parent
f91dffa0a4
commit
38ec79d038
|
|
@ -0,0 +1,61 @@
|
||||||
|
require 'debug'
|
||||||
|
|
||||||
|
# Generic FileHandler
|
||||||
|
class FileHandler
|
||||||
|
def initialize(file_path)
|
||||||
|
@file_path = file_path
|
||||||
|
end
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# FileHandler.new('/path_to_file').read_lines do |line|
|
||||||
|
# # process line
|
||||||
|
# end
|
||||||
|
def read_lines
|
||||||
|
File.foreach(@file_path, chomp: true).map do |line|
|
||||||
|
yield(line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Usage:
|
||||||
|
# file_content = FileHandler.new('/path_to_file').read_file(
|
||||||
|
def read_file
|
||||||
|
File.read(@file_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class PuzzleSolver
|
||||||
|
def initialize(file_handler, debug: false)
|
||||||
|
@handler = file_handler
|
||||||
|
@debug = debug
|
||||||
|
end
|
||||||
|
|
||||||
|
def debug(message)
|
||||||
|
puts message if @debug
|
||||||
|
end
|
||||||
|
|
||||||
|
def print_debug(message)
|
||||||
|
print message if @debug
|
||||||
|
end
|
||||||
|
|
||||||
|
def solve
|
||||||
|
raise NotImplementedError, 'Please implement this method in subclasses.'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: Puzzle-specific
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ARGV[0].nil? || ARGV[0].empty?
|
||||||
|
puts "Usage: ruby #{__FILE__} <file_name> [debug]"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
file_path = ARGV[0]
|
||||||
|
debug = (ARGV[1] == "debug")
|
||||||
|
file_handler = FileHandler.new(file_path)
|
||||||
|
|
||||||
|
## Puzzle-specific
|
||||||
|
cls = PuzzleSolver
|
||||||
|
##
|
||||||
|
|
||||||
|
puts "The answer is: #{cls.new(file_handler, debug:).solve}"
|
||||||
Loading…
Reference in New Issue