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.
6
7
8
9
10
11
12
13
|
# 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
|
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache.
4
5
6
|
# File 'lib/ldpath/result.rb', line 4
def cache
@cache
end
|
#loaded ⇒ Object
Returns the value of attribute loaded.
4
5
6
|
# File 'lib/ldpath/result.rb', line 4
def loaded
@loaded
end
|
#program ⇒ Object
Returns the value of attribute program.
4
5
6
|
# File 'lib/ldpath/result.rb', line 4
def program
@program
end
|
#uri ⇒ Object
Returns the value of attribute uri.
4
5
6
|
# File 'lib/ldpath/result.rb', line 4
def uri
@uri
end
|
Instance Method Details
#[](key) ⇒ Object
29
30
31
|
# File 'lib/ldpath/result.rb', line 29
def [](key)
evaluate(mappings.find { |x| x.name == key })
end
|
#context ⇒ Object
47
48
49
|
# File 'lib/ldpath/result.rb', line 47
def context
@context ||= load_graph(uri.to_s)
end
|
#func_call(fname, uri, context, *arguments) ⇒ Object
41
42
43
44
45
|
# 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) ⇒ Object
23
24
25
26
27
|
# 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) ⇒ Object
15
16
17
18
19
20
21
|
# 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
|
55
56
57
|
# File 'lib/ldpath/result.rb', line 55
def meta
@meta ||= {}
end
|
#prefixes ⇒ Object
51
52
53
|
# File 'lib/ldpath/result.rb', line 51
def prefixes
program.prefixes
end
|
#to_hash ⇒ Object
33
34
35
36
37
38
39
|
# 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
|