Class: Ldpath::Result
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Functions
#concat, #contains, #count, #earliest, #endsWith, #eq, #equals, #equalsIgnoreCase, #first, #flatten, #ge, #get, #gt, #isEmpty, #last, #latest, #le, #lt, #max, #min, #ne, #predicates, #replace, #round, #startsWith, #strJoin, #strLeft, #strRight, #strlen, #subList, #substr, #sum, #wc, #xpath
Constructor Details
#initialize(program, uri, cache: RDF::Util::Cache.new, context: nil, limit_to_context: false) ⇒ Result
Returns a new instance of Result.
10
11
12
13
14
15
16
17
|
# File 'lib/ldpath/result.rb', line 10
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
|
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
8
9
10
|
# File 'lib/ldpath/result.rb', line 8
def cache
@cache
end
|
#loaded ⇒ Object
Returns the value of attribute loaded.
8
9
10
|
# File 'lib/ldpath/result.rb', line 8
def loaded
@loaded
end
|
#program ⇒ Object
Returns the value of attribute program.
8
9
10
|
# File 'lib/ldpath/result.rb', line 8
def program
@program
end
|
#uri ⇒ Object
Returns the value of attribute uri.
8
9
10
|
# File 'lib/ldpath/result.rb', line 8
def uri
@uri
end
|
Instance Method Details
#[](key) ⇒ Object
31
32
33
|
# File 'lib/ldpath/result.rb', line 31
def [](key)
evaluate(mappings.find { |x| x.name == key })
end
|
#context ⇒ Object
49
50
51
|
# File 'lib/ldpath/result.rb', line 49
def context
@context ||= load_graph(uri.to_s)
end
|
#func_call(fname, uri, context, *arguments) ⇒ Object
43
44
45
46
47
|
# File 'lib/ldpath/result.rb', line 43
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) ⇒ Object
27
28
29
|
# File 'lib/ldpath/result.rb', line 27
def load_graph(uri)
cache[uri] ||= program.load(uri).tap { loaded[uri] = true }
end
|
#loading(uri, context) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/ldpath/result.rb', line 19
def loading(uri, context)
return unless /^http/.match?(uri.to_s)
return if loaded[uri.to_s]
context << load_graph(uri.to_s) unless limit_to_context?
context
end
|
55
56
57
|
# File 'lib/ldpath/result.rb', line 55
def meta
@meta ||= {}
end
|
#to_hash ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/ldpath/result.rb', line 35
def to_hash
h = mappings.each_with_object({}) do |mapping, hash|
hash[mapping.name] = evaluate(mapping).to_a
end
h.merge(meta)
end
|