Class: Ldpath::Program
- Inherits:
-
Object
- Object
- Ldpath::Program
- Defined in:
- lib/ldpath/program.rb
Constant Summary collapse
- ParseError =
Class.new StandardError
Instance Attribute Summary collapse
-
#default_loader ⇒ Object
readonly
Returns the value of attribute default_loader.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#loaders ⇒ Object
readonly
Returns the value of attribute loaders.
-
#mappings ⇒ Object
readonly
Returns the value of attribute mappings.
-
#prefixes ⇒ Object
readonly
Returns the value of attribute prefixes.
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(uri, context: nil, limit_to_context: false) ⇒ Object
-
#initialize(mappings, default_loader: Ldpath::Loaders::Direct.new, prefixes: {}, filters: [], loaders: {}) ⇒ Program
constructor
A new instance of Program.
- #load(uri) ⇒ Object
Constructor Details
#initialize(mappings, default_loader: Ldpath::Loaders::Direct.new, prefixes: {}, filters: [], loaders: {}) ⇒ Program
Returns a new instance of Program.
30 31 32 33 34 35 36 37 |
# 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 |
Instance Attribute Details
#default_loader ⇒ Object (readonly)
Returns the value of attribute default_loader.
29 30 31 |
# File 'lib/ldpath/program.rb', line 29 def default_loader @default_loader end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
29 30 31 |
# File 'lib/ldpath/program.rb', line 29 def filters @filters end |
#loaders ⇒ Object (readonly)
Returns the value of attribute loaders.
29 30 31 |
# File 'lib/ldpath/program.rb', line 29 def loaders @loaders end |
#mappings ⇒ Object (readonly)
Returns the value of attribute mappings.
29 30 31 |
# File 'lib/ldpath/program.rb', line 29 def mappings @mappings end |
#prefixes ⇒ Object (readonly)
Returns the value of attribute prefixes.
29 30 31 |
# File 'lib/ldpath/program.rb', line 29 def prefixes @prefixes end |
Class Method Details
.load(program) ⇒ Object
12 13 14 15 16 |
# 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 |
Instance Method Details
#evaluate(uri, context: nil, limit_to_context: false) ⇒ Object
39 40 41 42 43 44 45 46 |
# 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) ⇒ Object
48 49 50 51 52 53 |
# 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 |