Class: Ldpath::Program
- Inherits:
-
Object
- Object
- Ldpath::Program
- Includes:
- Functions
- Defined in:
- lib/ldpath/program.rb
Instance Attribute Summary collapse
-
#mappings ⇒ Object
readonly
Returns the value of attribute mappings.
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(uri, context = nil) ⇒ Object
- #func_call(fname, uri, context, *arguments) ⇒ Object
-
#initialize(mappings) ⇒ Program
constructor
A new instance of Program.
- #loading(uri, context) ⇒ Object
Methods included from Functions
#concat, #contains, #earliest, #endsWith, #eq, #equals, #equalsIgnoreCase, #first, #flatten, #ge, #get, #gt, #isEmpty, #last, #latest, #le, #lt, #max, #min, #ne, #replace, #round, #startsWith, #strJoin, #strLeft, #strRight, #strlen, #subList, #substr, #sum, #wc
Constructor Details
#initialize(mappings) ⇒ Program
Returns a new instance of Program.
25 26 27 28 |
# File 'lib/ldpath/program.rb', line 25 def initialize mappings @mappings ||= mappings @cache = {} end |
Instance Attribute Details
#mappings ⇒ Object (readonly)
Returns the value of attribute mappings.
24 25 26 |
# File 'lib/ldpath/program.rb', line 24 def mappings @mappings end |
Class Method Details
Instance Method Details
#evaluate(uri, context = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ldpath/program.rb', line 37 def evaluate uri, context = nil h = {} context ||= RDF::Graph.load uri.to_s mappings.each do |m| h[m.name] = case m.selector when Selector m.selector.evaluate(self, uri, context).map do |x| next x unless m.field_type RDF::Literal.new(x.to_s, datatype: m.field_type).canonicalize.object end else Array(m.selector) end end h end |
#func_call(fname, uri, context, *arguments) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ldpath/program.rb', line 56 def func_call fname, uri, context, *arguments if function_method? fname public_send(fname, uri, context, *arguments) else raise "No such function: #{fname}" end end |
#loading(uri, context) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/ldpath/program.rb', line 30 def loading uri, context if uri.to_s =~ /^http/ and !context.has_subject?(uri) @cache[uri] ||= RDF::Graph.load(uri) context << @cache[uri] end end |