odrl-ruby 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/odrl/rule.rb CHANGED
@@ -5,124 +5,112 @@ require_relative "odrl/version"
5
5
  # require "ODRL::Constraint"
6
6
 
7
7
  module ODRL
8
- class Rule < Base
9
- attr_accessor :uid, :constraints, :assets, :predicate, :type, :action, :assigner, :assignee
10
- def initialize(
11
- uid: nil,
12
- constraints: nil,
13
- assets: nil,
14
- predicate: nil,
15
- action: nil,
16
- assigner: nil,
17
- assignee: nil,
18
- type: CRULE,
19
- **args)
20
- @uid = uid
21
-
22
- unless @uid
23
- @uid = Base.baseURI + "#rule_" + Base.getuuid
24
- end
25
- super(uid: @uid, type: type, **args)
26
-
27
- @constraints = Hash.new
28
- @assets = Hash.new
29
- @assigner = Hash.new
30
- @assignee = Hash.new
31
- @action = Hash.new
32
-
33
- assets = [assets] unless assets.is_a? Array
34
- if !assets.first.nil?
35
- assets.each do |c|
36
- self.addAsset(asset: c)
37
- end
38
- end
39
- constraints = [constraints] unless constraints.is_a? Array
40
- if !constraints.first.nil?
41
- constraints.each do |c|
42
- self.addConstraint(constraint: c)
43
- end
44
- end
8
+ class Rule < Base
9
+ attr_accessor :uid, :constraints, :assets, :predicate, :type, :action, :assigner, :assignee
10
+
11
+ def initialize(
12
+ uid: nil,
13
+ constraints: nil,
14
+ assets: nil,
15
+ predicate: nil,
16
+ action: nil,
17
+ assigner: nil,
18
+ assignee: nil,
19
+ type: CRULE,
20
+ **args
21
+ )
22
+ @uid = uid
23
+
24
+ @uid ||= Base.baseURI + "#rule_" + Base.getuuid
25
+ super(uid: @uid, type: type, **args)
26
+
27
+ @constraints = {}
28
+ @assets = {}
29
+ @assigner = {}
30
+ @assignee = {}
31
+ @action = {}
32
+
33
+ assets = [assets] unless assets.is_a? Array
34
+ unless assets.first.nil?
35
+ assets.each do |c|
36
+ addAsset(asset: c)
45
37
  end
38
+ end
39
+ constraints = [constraints] unless constraints.is_a? Array
40
+ return if constraints.first.nil?
46
41
 
42
+ constraints.each do |c|
43
+ addConstraint(constraint: c)
44
+ end
45
+ end
47
46
 
48
- def addAsset(asset:)
49
- unless asset.is_a?(Asset)
50
- raise "Asset is not an ODRL Asset"
51
- else
52
- uid = asset.uid
53
- self.assets[uid] = [PASSET, asset]
54
- end
55
- end
47
+ def addAsset(asset:)
48
+ raise "Asset is not an ODRL Asset" unless asset.is_a?(Asset)
56
49
 
57
- def addConstraint(constraint:)
58
- unless constraint.is_a?(Constraint)
59
- raise "Constraint is not an ODRL Constraint"
60
- else
61
- self.constraints[constraint.uid] = [PCONSTRAINT, constraint]
62
- end
63
- end
50
+ uid = asset.uid
51
+ assets[uid] = [PASSET, asset]
52
+ end
64
53
 
65
- def addAction(action:)
66
- unless action.is_a?(Action)
67
- raise "Action is not an ODRL Action"
68
- else
69
- self.action[action.uid] = [PACTION, action]
70
- end
71
- end
54
+ def addConstraint(constraint:)
55
+ raise "Constraint is not an ODRL Constraint" unless constraint.is_a?(Constraint)
72
56
 
73
- def addAssigner(party:)
74
- unless party.is_a?(Party)
75
- raise "Assigner is not an ODRL Party"
76
- else
77
- self.assigner[party.uid] = [PASSIGNER, party]
78
- end
79
- end
57
+ constraints[constraint.uid] = [PCONSTRAINT, constraint]
58
+ end
80
59
 
81
- def addAssignee(party:)
82
- unless party.is_a?(Party)
83
- raise "Asigner is not an ODRL Party"
84
- else
85
- self.assignee[party.uid] = [PASSIGNEE, party]
86
- end
87
- end
60
+ def addAction(action:)
61
+ raise "Action is not an ODRL Action" unless action.is_a?(Action)
88
62
 
89
- def load_graph
90
- super
91
- [:constraints, :assets, :action, :assigner, :assignee].each do |connected_object_type|
92
- next unless self.send(connected_object_type)
93
- self.send(connected_object_type).each do |uid, typedconnection|
94
- predicate, odrlobject = typedconnection # e.g. "action", ActionObject
95
- object = odrlobject.uid
96
- subject = self.uid
97
- repo = self.repository
98
- triplify(subject, predicate, object, repo)
99
- odrlobject.load_graph # start the cascade
100
- end
101
- end
102
- end
63
+ self.action[action.uid] = [PACTION, action]
64
+ end
103
65
 
104
- def serialize(format:)
105
- super
106
- end
66
+ def addAssigner(party:)
67
+ raise "Assigner is not an ODRL Party" unless party.is_a?(Party)
68
+
69
+ assigner[party.uid] = [PASSIGNER, party]
107
70
  end
108
71
 
72
+ def addAssignee(party:)
73
+ raise "Asigner is not an ODRL Party" unless party.is_a?(Party)
109
74
 
110
- class Permission < Rule
111
- def initialize(predicate: PPERMISSION, type: CPERMISSION, **args)
112
- super(predicate: predicate, type: type, **args)
113
- end
75
+ assignee[party.uid] = [PASSIGNEE, party]
114
76
  end
115
77
 
116
- class Duty < Rule
117
- def initialize(predicate: PDUTY, type: CDUTY, **args)
118
- super(predicate: predicate, type: type, **args)
78
+ def load_graph
79
+ super
80
+ %i[constraints assets action assigner assignee].each do |connected_object_type|
81
+ next unless send(connected_object_type)
82
+
83
+ send(connected_object_type).each do |_uid, typedconnection|
84
+ predicate, odrlobject = typedconnection # e.g. "action", ActionObject
85
+ object = odrlobject.uid
86
+ subject = uid
87
+ repo = repository
88
+ triplify(subject, predicate, object, repo)
89
+ odrlobject.load_graph # start the cascade
119
90
  end
91
+ end
120
92
  end
121
93
 
122
- class Prohibition < Rule
123
- def initialize(predicate: PPROHIBITION, type: CPROHIBITION, **args)
124
- super(predicate: predicate, type: type, **args)
125
- end
94
+ def serialize(format:)
95
+ super
126
96
  end
97
+ end
127
98
 
99
+ class Permission < Rule
100
+ def initialize(predicate: PPERMISSION, type: CPERMISSION, **args)
101
+ super(predicate: predicate, type: type, **args)
102
+ end
103
+ end
104
+
105
+ class Duty < Rule
106
+ def initialize(predicate: PDUTY, type: CDUTY, **args)
107
+ super(predicate: predicate, type: type, **args)
108
+ end
109
+ end
110
+
111
+ class Prohibition < Rule
112
+ def initialize(predicate: PPROHIBITION, type: CPROHIBITION, **args)
113
+ super(predicate: predicate, type: type, **args)
114
+ end
115
+ end
128
116
  end
metadata CHANGED
@@ -1,16 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odrl-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Wilkinson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-28 00:00:00.000000000 Z
11
+ date: 2023-06-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: builds ODRL files nicely.
13
+ description: A builder for ODRL files. Does basic validation against core ODRL vocabularies.
14
+ Has a Builder that allows you to create ODRL Profiles to extend the core vocabulary. DOES
15
+ NOT validate against a profile. DOES NOT cover the full ODRL specificaiton, only
16
+ the bits that I needed!
14
17
  email:
15
18
  - markw@illuminae.com
16
19
  executables: []
@@ -26,9 +29,11 @@ files:
26
29
  - Rakefile
27
30
  - bin/console
28
31
  - bin/setup
29
- - examples/builder-translator-output.ttl
32
+ - examples/biohackathon-output.ttl
33
+ - examples/build_profile.rb
30
34
  - examples/create-biohackathon-offer.rb
31
- - examples/output.ttl
35
+ - examples/create-nagoya-es-offer.rb
36
+ - examples/nagoya-output.ttl
32
37
  - launch.json
33
38
  - lib/odrl/action.rb
34
39
  - lib/odrl/asset.rb
@@ -37,6 +42,7 @@ files:
37
42
  - lib/odrl/odrl/version.rb
38
43
  - lib/odrl/party.rb
39
44
  - lib/odrl/policy.rb
45
+ - lib/odrl/profile/builder.rb
40
46
  - lib/odrl/ruby.rb
41
47
  - lib/odrl/rule.rb
42
48
  homepage: https://example.org
File without changes
File without changes