Class: RDFMapper::Scope::Condition
- Inherits:
-
Object
- Object
- RDFMapper::Scope::Condition
- Defined in:
- lib/lib/scope/condition.rb
Overview
- -
Instance Attribute Summary collapse
-
#eq ⇒ Object
readonly
Returns the value of attribute eq.
Instance Method Summary collapse
-
#initialize(cls, att, value, eq = '=') ⇒ Condition
constructor
A new instance of Condition.
-
#inspect ⇒ String
Developer-friendly representation of the instance.
-
#matches?(object) ⇒ Boolean
Checks whether specified object passes all conditions of the query.
-
#name ⇒ Object
[-].
-
#to_statements(subject) ⇒ Object
[-].
-
#to_triples(subject) ⇒ Object
[-].
-
#value(required = []) ⇒ Object
(also: #check)
[-].
Constructor Details
#initialize(cls, att, value, eq = '=') ⇒ Condition
Returns a new instance of Condition.
10 11 12 |
# File 'lib/lib/scope/condition.rb', line 10 def initialize(cls, att, value, eq = '=') @cls, @att, @value, @eq = cls, att, value, eq end |
Instance Attribute Details
#eq ⇒ Object (readonly)
Returns the value of attribute eq.
8 9 10 |
# File 'lib/lib/scope/condition.rb', line 8 def eq @eq end |
Instance Method Details
#inspect ⇒ String
Developer-friendly representation of the instance.
79 80 81 |
# File 'lib/lib/scope/condition.rb', line 79 def inspect #nodoc "#<Condition:(%s%s%s)>" % [name, eq, value] end |
#matches?(object) ⇒ Boolean
Checks whether specified object passes all conditions of the query.
42 43 44 |
# File 'lib/lib/scope/condition.rb', line 42 def matches?(object) object.send(name) == value end |
#name ⇒ Object
- -
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/lib/scope/condition.rb', line 17 def name if @att == :id return @att end if att = @cls.has?(@att) att.name else @att end end |
#to_statements(subject) ⇒ Object
- -
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/lib/scope/condition.rb', line 58 def to_statements(subject) if association? object = association.id rdf_type = association.to_triples(:short => true) else object = RDF::Query::Variable.new object.bind(value, eq) rdf_type = [] end rdf_type + [{ :subject => subject, :predicate => @cls.has?(@att).type, :object => object }] end |
#to_triples(subject) ⇒ Object
- -
49 50 51 52 53 |
# File 'lib/lib/scope/condition.rb', line 49 def to_triples(subject) to_statements(subject).map do |statement| [ statement[:subject], statement[:predicate], statement[:object] ] end end |
#value(required = []) ⇒ Object Also known as: check
- -
31 32 33 |
# File 'lib/lib/scope/condition.rb', line 31 def value(required = []) association? ? association(required) : literal end |