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
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#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, options = {}) ⇒ Program
constructor
A new instance of Program.
Constructor Details
#initialize(mappings, options = {}) ⇒ Program
Returns a new instance of Program.
30 31 32 33 34 |
# File 'lib/ldpath/program.rb', line 30 def initialize(mappings, = {}) @mappings ||= mappings @prefixes = [:prefixes] || {} @filters = [:filters] || [] end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
29 30 31 |
# File 'lib/ldpath/program.rb', line 29 def filters @filters 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
36 37 38 39 40 41 42 43 |
# File 'lib/ldpath/program.rb', line 36 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 |