Class: ODRL::Party
Direct Known Subclasses
Instance Attribute Summary collapse
-
#partOf ⇒ Object
Returns the value of attribute partOf.
-
#predicate ⇒ Object
Returns the value of attribute predicate.
-
#refinements ⇒ Object
Returns the value of attribute refinements.
-
#type ⇒ Object
Returns the value of attribute type.
-
#uid ⇒ Object
Returns the value of attribute uid.
Attributes inherited from Base
#baseURI, #creator, #description, #id, #issued, #label, #subject, #title
Instance Method Summary collapse
- #addPart(part: args) ⇒ Object
- #addRefinement(refinement: args) ⇒ Object
-
#initialize(uid: nil, refinements: nil, partOf: nil, predicate: nil, type: CPARTY, **args) ⇒ Party
constructor
A new instance of Party.
- #load_graph ⇒ Object
- #serialize(format:) ⇒ Object
Methods inherited from Base
baseURI, clear_repository, #get_writer, getuuid, repository, #repository, #triplify
Constructor Details
#initialize(uid: nil, refinements: nil, partOf: nil, predicate: nil, type: CPARTY, **args) ⇒ Party
Returns a new instance of Party.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/odrl/party.rb', line 7 def initialize( uid: nil, refinements: nil, partOf: nil, predicate: nil, type: CPARTY, **args ) @uid = uid @uid ||= Base.baseURI + "#party_" + Base.getuuid super(uid: @uid, type: type, **args) @refinements = {} @partOf = {} @predicate = predicate.to_s if @predicate&.match(/https?:/) # do nothing! It's their choice to send a full predicate! elsif @predicate # we're guessing it will be a string from the valid list? unless PARTYFUNCTIONS.include? @predicate raise "You didn't indicate a valid predicate" # @predicate = ODRLV.assigner else @predicate = "#{ODRLV.to_s}#{predicate}" # make the URI form of the valid predicate end elsif @predicate.nil? raise "If you don't indicate a predicate at all" # @predicate = ODRLV.assigner end refinements = [refinements] unless refinements.is_a? Array unless refinements.first.nil? refinements.each do |c| addRefinement(refinement: c) end end partOf = [partOf] unless partOf.is_a? Array unless partOf.first.nil? partOf.each do |p| p.addPart(part: self) end end unless @partOf and !(@partOf.is_a? PartyCollection) # if it exists and is the wrong type raise "The parent collection of a Party must be of type ODRL::PaertyCollection." end end |
Instance Attribute Details
#partOf ⇒ Object
Returns the value of attribute partOf.
5 6 7 |
# File 'lib/odrl/party.rb', line 5 def partOf @partOf end |
#predicate ⇒ Object
Returns the value of attribute predicate.
5 6 7 |
# File 'lib/odrl/party.rb', line 5 def predicate @predicate end |
#refinements ⇒ Object
Returns the value of attribute refinements.
5 6 7 |
# File 'lib/odrl/party.rb', line 5 def refinements @refinements end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/odrl/party.rb', line 5 def type @type end |
#uid ⇒ Object
Returns the value of attribute uid.
5 6 7 |
# File 'lib/odrl/party.rb', line 5 def uid @uid end |
Instance Method Details
#addPart(part: args) ⇒ Object
64 65 66 67 |
# File 'lib/odrl/party.rb', line 64 def addPart(part: args) raise "Party cannot be added as part of something that is not an PartyCollection" unless self.is_a?(PartyCollection) part.partOf[uid] = [PPARTOF, self] end |
#addRefinement(refinement: args) ⇒ Object
58 59 60 61 62 |
# File 'lib/odrl/party.rb', line 58 def addRefinement(refinement: args) raise "Refinement is not an ODRL Constraint" unless refinement.is_a?(Constraint) refinements[refinement.uid] = [PREFINEMENT, refinement] end |
#load_graph ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/odrl/party.rb', line 69 def load_graph super # TODO: This is bad DRY!! Put the bulk of this method into the base object # TODO: Currently we don't support partOf %i[refinements].each do |connected_object_type| next unless send(connected_object_type) send(connected_object_type).each do |_uid, typedconnection| predicate, odrlobject = typedconnection # e.g. "refinement", RefinementObject object = odrlobject.uid subject = uid repo = repository triplify(subject, predicate, object, repo) odrlobject.load_graph # start the cascade end end end |
#serialize(format:) ⇒ Object
87 88 89 |
# File 'lib/odrl/party.rb', line 87 def serialize(format:) super end |