class Ldpath::Program
Constants
- ParseError
Attributes
default_loader[R]
filters[R]
loaders[R]
mappings[R]
prefixes[R]
Public Class Methods
load(program)
click to toggle source
# File lib/ldpath/program.rb, line 12 def load(program) parser.parse(program, reporter: Parslet::ErrorReporter::Deepest.new) rescue Parslet::ParseFailed => e raise ParseError, e.parse_failure_cause.ascii_tree end
new(mappings, default_loader: Ldpath::Loaders::Direct.new, prefixes: {}, filters: [], loaders: {})
click to toggle source
# File lib/ldpath/program.rb, line 30 def initialize(mappings, default_loader: Ldpath::Loaders::Direct.new, prefixes: {}, filters: [], loaders: {}) @mappings ||= mappings @default_loader = default_loader @loaders = loaders @prefixes = prefixes @filters = filters end
parse(program, transform_context = {})
click to toggle source
# File lib/ldpath/program.rb, line 6 def parse(program, transform_context = {}) ast = transform.apply load(program), transform_context Ldpath::Program.new ast.compact, transform_context end
Private Class Methods
parser()
click to toggle source
# File lib/ldpath/program.rb, line 24 def parser @parser ||= Ldpath::Parser.new end
transform()
click to toggle source
# File lib/ldpath/program.rb, line 20 def transform Ldpath::Transform.new end
Public Instance Methods
evaluate(uri, context: nil, limit_to_context: false)
click to toggle source
# File lib/ldpath/program.rb, line 39 def evaluate(uri, context: nil, limit_to_context: false) result = Ldpath::Result.new(self, uri, context: context, limit_to_context: limit_to_context) unless filters.empty? return {} unless filters.all? { |f| f.evaluate(result, uri, result.context) } end result.to_hash end
load(uri)
click to toggle source
# File lib/ldpath/program.rb, line 48 def load(uri) loader = loaders.find { |k, v| uri =~ k }&.last loader ||= default_loader loader.load(uri) end