Class: ODRL::Rule
Direct Known Subclasses
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#assets ⇒ Object
Returns the value of attribute assets.
-
#assignee ⇒ Object
Returns the value of attribute assignee.
-
#assigner ⇒ Object
Returns the value of attribute assigner.
-
#constraints ⇒ Object
Returns the value of attribute constraints.
-
#predicate ⇒ Object
Returns the value of attribute predicate.
-
#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
- #addAction(action:) ⇒ Object
- #addAsset(asset:) ⇒ Object
- #addAssignee(party:) ⇒ Object
- #addAssigner(party:) ⇒ Object
- #addConstraint(constraint:) ⇒ Object
-
#initialize(uid: nil, constraints: nil, assets: nil, predicate: nil, action: nil, assigner: nil, assignee: nil, type: CRULE, **args) ⇒ Rule
constructor
A new instance of Rule.
- #load_graph ⇒ Object
- #serialize(format:) ⇒ Object
Methods inherited from Base
baseURI, clear_repository, #get_writer, getuuid, repository, #repository, #triplify
Constructor Details
#initialize(uid: nil, constraints: nil, assets: nil, predicate: nil, action: nil, assigner: nil, assignee: nil, type: CRULE, **args) ⇒ Rule
Returns a new instance of Rule.
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 |
# File 'lib/odrl/rule.rb', line 11 def initialize( uid: nil, constraints: nil, assets: nil, predicate: nil, action: nil, assigner: nil, assignee: nil, type: CRULE, **args ) @uid = uid @uid ||= Base.baseURI + "#rule_" + Base.getuuid super(uid: @uid, type: type, **args) @constraints = {} @assets = {} @assigner = {} @assignee = {} @action = {} assets = [assets] unless assets.is_a? Array unless assets.first.nil? assets.each do |c| addAsset(asset: c) end end constraints = [constraints] unless constraints.is_a? Array return if constraints.first.nil? constraints.each do |c| addConstraint(constraint: c) end end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
9 10 11 |
# File 'lib/odrl/rule.rb', line 9 def action @action end |
#assets ⇒ Object
Returns the value of attribute assets.
9 10 11 |
# File 'lib/odrl/rule.rb', line 9 def assets @assets end |
#assignee ⇒ Object
Returns the value of attribute assignee.
9 10 11 |
# File 'lib/odrl/rule.rb', line 9 def assignee @assignee end |
#assigner ⇒ Object
Returns the value of attribute assigner.
9 10 11 |
# File 'lib/odrl/rule.rb', line 9 def assigner @assigner end |
#constraints ⇒ Object
Returns the value of attribute constraints.
9 10 11 |
# File 'lib/odrl/rule.rb', line 9 def constraints @constraints end |
#predicate ⇒ Object
Returns the value of attribute predicate.
9 10 11 |
# File 'lib/odrl/rule.rb', line 9 def predicate @predicate end |
#type ⇒ Object
Returns the value of attribute type.
9 10 11 |
# File 'lib/odrl/rule.rb', line 9 def type @type end |
#uid ⇒ Object
Returns the value of attribute uid.
9 10 11 |
# File 'lib/odrl/rule.rb', line 9 def uid @uid end |
Instance Method Details
#addAction(action:) ⇒ Object
60 61 62 63 64 |
# File 'lib/odrl/rule.rb', line 60 def addAction(action:) raise "Action is not an ODRL Action" unless action.is_a?(Action) self.action[action.uid] = [PACTION, action] end |
#addAsset(asset:) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/odrl/rule.rb', line 47 def addAsset(asset:) raise "Asset is not an ODRL Asset" unless asset.is_a?(Asset) uid = asset.uid assets[uid] = [PASSET, asset] end |
#addAssignee(party:) ⇒ Object
72 73 74 75 76 |
# File 'lib/odrl/rule.rb', line 72 def addAssignee(party:) raise "Asigner is not an ODRL Party" unless party.is_a?(Party) assignee[party.uid] = [PASSIGNEE, party] end |
#addAssigner(party:) ⇒ Object
66 67 68 69 70 |
# File 'lib/odrl/rule.rb', line 66 def addAssigner(party:) raise "Assigner is not an ODRL Party" unless party.is_a?(Party) assigner[party.uid] = [PASSIGNER, party] end |
#addConstraint(constraint:) ⇒ Object
54 55 56 57 58 |
# File 'lib/odrl/rule.rb', line 54 def addConstraint(constraint:) raise "Constraint is not an ODRL Constraint" unless constraint.is_a?(Constraint) constraints[constraint.uid] = [PCONSTRAINT, constraint] end |
#load_graph ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/odrl/rule.rb', line 78 def load_graph super %i[constraints assets action assigner assignee].each do |connected_object_type| next unless send(connected_object_type) send(connected_object_type).each do |_uid, typedconnection| predicate, odrlobject = typedconnection # e.g. "action", ActionObject object = odrlobject.uid subject = uid repo = repository triplify(subject, predicate, object, repo) odrlobject.load_graph # start the cascade end end end |
#serialize(format:) ⇒ Object
94 95 96 |
# File 'lib/odrl/rule.rb', line 94 def serialize(format:) super end |