Class: RDF::Property
- Inherits:
-
RDFS::Resource
- Object
- RDFS::Resource
- RDF::Property
- Defined in:
- lib/active_rdf/objectmanager/property.rb
Overview
Represents an RDF property. If an optional subject is provided on instatiation, provides access to values of this property belonging to the associated subject. Property objects are Enumerable
. Values are returned as copies with no order garunteed and may be accessed individually by key.
Usage
age = RDF::Property.new('http://activerdf.org/test/age')
age.domain => [#<RDFS::Resource @uri="http://activerdf.org/test/Person">]
age.range => [#<RDFS::Resource @uri="http://www.w3.org/1999/02/22-rdf-syntax-ns#Literal">]
age.type => [#<RDFS::Resource @uri="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property">]
age.to_a => ActiveRdfError: http://activerdf.org/test/age: no associated subject
email = RDF::Property.new('http://activerdf.org/test/email', 'http://activerdf.org/test/eyal')
email.replace("[email protected]") # replace any existing values
email.add("[email protected]") # add new value to this property
email += ("[email protected]") # alternative way to add new value
email.clear # delete any existing values
email.add(["[email protected]","[email protected]"]) # add array containing values
email["[email protected]"] = "[email protected]" # replace existing value
email[p.index("[email protected]")] = "[email protected]" # replace existing value by key
email.include?("[email protected]") => true # check for existing value
email == ["[email protected]","[email protected]"] => true # compare value(s) to array (order is ignored)
email.delete("[email protected]") # delete specific value
email == "[email protected]" => true # compare value(s) to single value
email.collect!{|val| val.gsub(/@/,' at ').gsub(/\./,' dot ')} # update value(s) with result of block
Instance Attribute Summary collapse
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Attributes inherited from RDFS::Resource
Instance Method Summary collapse
-
#initialize(property, subject = nil) ⇒ Property
constructor
A new instance of Property.
- #initialize_copy(property) ⇒ Object
-
#property ⇒ Object
Returns the property object for this property without @subject set.
Methods inherited from RDFS::Resource
#<=>, ==, #==, #abbr, #abbr?, #abbreviation, #class_level_predicates, #class_predicates, #class_properties, #classes, #contexts, #direct_predicates, #direct_properties, #direct_types, #empty_predicates, #empty_properties, eql?, find, find_all, find_by, #hash, #inspect, #instance_of?, #instance_predicates, #instance_properties, #is_a?, #localname, localname, #method_missing, method_missing, #new_record?, predicates, #predicates, properties, #properties, #register_predicate, #save, #sub_predicates, #sub_properties, #super_classes, #super_predicates, #super_properties, #super_types, #to_literal_s, #to_xml, #type, #type=, #types, uri
Constructor Details
#initialize(property, subject = nil) ⇒ Property
Returns a new instance of Property.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_rdf/objectmanager/property.rb', line 33 def initialize(property, subject = nil) super(property) @subject = subject @lang = nil @exact_lang = true @datatype = nil @context = nil if @subject class<<self include AssociatedProperty end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RDFS::Resource
Instance Attribute Details
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
31 32 33 |
# File 'lib/active_rdf/objectmanager/property.rb', line 31 def subject @subject end |
Instance Method Details
#initialize_copy(property) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/active_rdf/objectmanager/property.rb', line 50 def initialize_copy(property) if @subject class<<self include AssociatedProperty end end end |