Class: Prolego::Query

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

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ Query

Returns a new instance of Query.



6
7
8
# File 'lib/prolego.rb', line 6

def initialize filepath
  @file=filepath
end

Instance Method Details

#command(predicate, args) ⇒ Object



10
11
12
# File 'lib/prolego.rb', line 10

def command predicate,args
  @output=%x[swipl -q -f '#{@file}' -g '#{parg predicate}(#{parg args}),halt']
end

#epilogObject



18
19
20
# File 'lib/prolego.rb', line 18

def epilog
  @output.lines.map {|x| x.slice(/.*d/).split("------").join " "}
end

#parg(arg) ⇒ Object



14
15
16
# File 'lib/prolego.rb', line 14

def parg arg
  arg.to_s.gsub /^\[|"|'|\]$/, "[" => "", "]" => "", "'" => "'\"'\"'", "\"" => "'\"'\"'"
end