Class: Wongi::Engine::Template
- Inherits:
-
Struct
- Object
- Struct
- Wongi::Engine::Template
- Defined in:
- lib/wongi-engine/template.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
-
#predicate ⇒ Object
Returns the value of attribute predicate.
-
#subject ⇒ Object
Returns the value of attribute subject.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #=~(template) ⇒ Object
- #hash ⇒ Object
- #inspect ⇒ Object
- #resolve!(token) ⇒ Object
-
#root? ⇒ Boolean
TODO: reintroduce Network#import when bringing back RDF support.
- #to_s ⇒ Object
- #variables ⇒ Object
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object
3 4 5 |
# File 'lib/wongi-engine/template.rb', line 3 def object @object end |
#predicate ⇒ Object
Returns the value of attribute predicate
3 4 5 |
# File 'lib/wongi-engine/template.rb', line 3 def predicate @predicate end |
#subject ⇒ Object
Returns the value of attribute subject
3 4 5 |
# File 'lib/wongi-engine/template.rb', line 3 def subject @subject end |
Class Method Details
.hash_for(*args) ⇒ Object
28 29 30 |
# File 'lib/wongi-engine/template.rb', line 28 def self.hash_for *args args.map( &:hash ).hash end |
.variable?(thing) ⇒ Boolean
5 6 7 8 |
# File 'lib/wongi-engine/template.rb', line 5 def self.variable? thing return false unless thing.is_a?(Symbol) thing[0] >= 'A' && thing[0] <= 'Z' end |
Instance Method Details
#==(other) ⇒ Object
32 33 34 |
# File 'lib/wongi-engine/template.rb', line 32 def == other other.is_a?(Template) && subject == other.subject && predicate == other.predicate && object == other.object end |
#=~(template) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wongi-engine/template.rb', line 36 def =~ template case template when Template ( template.subject == :_ || template.subject == subject ) && ( template.predicate == :_ || template.predicate == predicate ) && ( template.object == :_ || template.object == object ) else raise Error, "templates can only match other templates" end end |
#hash ⇒ Object
24 25 26 |
# File 'lib/wongi-engine/template.rb', line 24 def hash @hash ||= [subject.hash, predicate.hash, object.hash].hash end |
#inspect ⇒ Object
47 48 49 |
# File 'lib/wongi-engine/template.rb', line 47 def inspect "<~#{subject.inspect} #{predicate.inspect} #{object.inspect}>" end |
#resolve!(token) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wongi-engine/template.rb', line 55 def resolve!(token) s = if Template.variable?(subject) token[subject].tap { |x| raise DefinitionError, "unbound variable #{subject} in token #{token}" unless x} else subject end p = if Template.variable?(predicate) token[predicate].tap { |x| raise DefinitionError, "unbound variable #{predicate} in token #{token}" unless x} else predicate end o = if Template.variable?(object) token[object].tap { |x| raise DefinitionError, "unbound variable #{object} in token #{token}" unless x} else object end [s, p, o] end |
#root? ⇒ Boolean
TODO: reintroduce Network#import when bringing back RDF support
12 13 14 |
# File 'lib/wongi-engine/template.rb', line 12 def root? subject == :_ && predicate == :_ && object == :_ end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/wongi-engine/template.rb', line 51 def to_s inspect end |