class Prolego::Query
Attributes
error[R]
output[R]
status[R]
whiny[R]
Public Class Methods
new(filepath, whiny: false)
click to toggle source
# File lib/prolego.rb, line 10 def initialize(filepath, whiny: false) @file = filepath @whiny = whiny end
Public Instance Methods
command(predicate, args)
click to toggle source
# File lib/prolego.rb, line 15 def command(predicate, args) command = "swipl -qf '#{@file}' -g '#{escape(predicate)}(#{escape(args)}),halt'" @output, @error, status = Open3.capture3(command) (@status = status.exitstatus) == 0 end
epilog()
click to toggle source
# File lib/prolego.rb, line 25 def epilog fail "Prolog exit status #{@status}. Check errors with Query#error" if @status != 0 && whiny JSON.parse @output.gsub("'", "\"") rescue @output end
escape(arg)
click to toggle source
# File lib/prolego.rb, line 21 def escape(arg) arg.to_s.gsub(/^\[|"|'|\]$/, "[" => "", "]" => "", "'" => "'\"'\"'", "\"" => "'\"'\"'") end