class Ldpath::Result

Attributes

cache[R]
loaded[R]
program[R]
uri[R]

Public Class Methods

new(program, uri, cache: RDF::Util::Cache.new, context: nil, limit_to_context: false) click to toggle source
# File lib/ldpath/result.rb, line 6
def initialize(program, uri, cache: RDF::Util::Cache.new, context: nil, limit_to_context: false)
  @program = program
  @uri = uri
  @cache = cache
  @loaded = {}
  @context = context
  @limit_to_context = limit_to_context
end

Public Instance Methods

[](key) click to toggle source
# File lib/ldpath/result.rb, line 29
def [](key)
  evaluate(mappings.find { |x| x.name == key })
end
context() click to toggle source
# File lib/ldpath/result.rb, line 47
def context
  @context ||= load_graph(uri.to_s)
end
func_call(fname, uri, context, *arguments) click to toggle source
# File lib/ldpath/result.rb, line 41
def func_call(fname, uri, context, *arguments)
  raise "No such function: #{fname}" unless function_method? fname

  public_send(fname, uri, context, *arguments)
end
load_graph(uri) click to toggle source
# File lib/ldpath/result.rb, line 23
def load_graph(uri)
  cache[uri] ||= begin
    program.load(uri).tap { loaded[uri] = true }
  end
end
loading(uri, context) click to toggle source
# File lib/ldpath/result.rb, line 15
def loading(uri, context)
  return unless uri.to_s =~ /^http/
  return if loaded[uri.to_s]

  context << load_graph(uri.to_s) unless limit_to_context?
  context
end
meta() click to toggle source
# File lib/ldpath/result.rb, line 55
def meta
  @meta ||= {}
end
prefixes() click to toggle source
# File lib/ldpath/result.rb, line 51
def prefixes
  program.prefixes
end
to_hash() click to toggle source
# File lib/ldpath/result.rb, line 33
def to_hash
  h = mappings.each_with_object({}) do |mapping, hash|
    hash[mapping.name] = evaluate(mapping).to_a
  end

  h.merge(meta)
end

Private Instance Methods

evaluate(mapping) click to toggle source
# File lib/ldpath/result.rb, line 61
def evaluate(mapping)
  mapping.evaluate(self, uri, context)
end
function_method?(function) click to toggle source
# File lib/ldpath/result.rb, line 65
def function_method?(function)
  Functions.public_instance_methods(false).include? function.to_sym
end
limit_to_context?() click to toggle source
# File lib/ldpath/result.rb, line 73
def limit_to_context?
  @limit_to_context
end
mappings() click to toggle source
# File lib/ldpath/result.rb, line 69
def mappings
  program.mappings
end