odrl-ruby 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e96a449f1af06d063a0a7e7f60b9fe1785c150a5370774336b5967b049b98a5b
4
- data.tar.gz: 9e4e6b649170abea6f73afe667e7f9368a713d8cfaf81b08bfa76c31ac6b2c9e
3
+ metadata.gz: 920e72e3d22ebf2895fa79bb43bd0a5e5b7d257ffad35bc3a8920a9b2d140649
4
+ data.tar.gz: 663462477a5b32043293afa56148d2fde102a88bcfe285672d7fa157277ec48d
5
5
  SHA512:
6
- metadata.gz: d85cc899a5b73c9a1e48d0df3b1e87eca4e7a2d711c074a6988cec7b58570d3c09b9f21dd3fe7f2b72fa432efefe25885d64e901d7bd0835f8d4176f4e025f65
7
- data.tar.gz: 4b6538ebe4be2c357da2b5ea41d2ca4db21b3e61e7413ebba5bbdd75cd4642854d1936f2d43201e138d80906b793dc19b7bcd3ba458ee8f724428efc887fd221
6
+ metadata.gz: c787e947589f888aab1e31f0a429713de6311600e3f5503d8638c1ed73fcd1e585f0b715dccda80cd625a96820b5a226533f83cf48f95581a2fb646b85aaf8aa
7
+ data.tar.gz: c9f4028606c82de1216c58865131c67060f647b09942ff31ad9b2432b2ccaacf3a32114e67cd9324280055ef7b3ad78ff0fe5eb18200b345389969f96e076395
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 3
3
3
 
4
4
  Style/StringLiterals:
5
5
  Enabled: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- odrl-ruby (0.1.0)
4
+ odrl-ruby (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/odrl/action.rb CHANGED
@@ -2,28 +2,28 @@
2
2
 
3
3
  module ODRL
4
4
 
5
- class Action < Base
6
- # ODRL::Action
7
- # Describes an action like "use"
8
- #
9
- # @author Mark D Wilkinson
10
- # @attr [URI] (optional) uid the URI of the Action node
11
- # @attr [[ODRL::Refinement]] (optional) ODRL Refinement objects
12
- # @attr [URI] predicate (optional) the predicate you wish to use with this action
13
- # @attr [string] value (required) a string like "use"
14
- # @attr [string] vallabel (optional) a string like "use"
5
+ # ODRL::Action
6
+ # Describes an action like "use"
7
+ #
8
+ # @author Mark D Wilkinson
9
+ # @attr [URI] (optional) uid the URI of the Action node
10
+ # @attr [[ODRL::Refinement]] (optional) ODRL Refinement objects
11
+ # @attr [URI] predicate (optional) the predicate you wish to use with this action
12
+ # @attr [string] value (required) a string like "use"
13
+ # @attr [string] vallabel (optional) a string like "use"
14
+ class Action < Base
15
15
 
16
16
  attr_accessor :uid, :refinements, :predicate, :type, :value, :vallabel
17
17
 
18
18
 
19
19
  # constructor
20
20
  # @param [Hash] opts the options to create a message with.
21
- # @option :value the string value of rthe action, like "use"
22
- # @option :vallabel the string for the label, like "use"
21
+ # @option opts [String] :value the string value of rthe action, like "use"
22
+ # @option opts [String] :vallabel the string for the label, like "use"
23
23
  #
24
- def initialize(args)
25
- @value = args[:value]
26
- @vallabel = args[:value]
24
+ def initialize(value:, vallabel: "", type: CACTION, **args)
25
+ @value = value
26
+ @vallabel = vallabel || @value
27
27
  raise "Actions must haves a value such as 'use' - I'm dead!" unless @value
28
28
  @value = "http://www.w3.org/ns/odrl/2/#{@value}" unless @value =~ /http:\/\// # if it is already a URI, then let it go
29
29
 
@@ -31,9 +31,8 @@ module ODRL
31
31
  # unless @uid
32
32
  # self.uid = Base.baseURI + "#action_" + Base.getuuid
33
33
  # end
34
- super(args.merge({uid: @uid}))
34
+ super(uid: @uid, type: type, **args)
35
35
 
36
- self.type="http://www.w3.org/ns/odrl/2/Action"
37
36
 
38
37
  @refinements = Hash.new
39
38
 
@@ -102,15 +101,13 @@ module ODRL
102
101
 
103
102
 
104
103
  class Use < Action
105
- def initialize(args)
106
- super(args)
107
- self.type = "http://www.w3.org/ns/odrl/2/Action" unless self.type
104
+ def initialize(type: CACTION, **args)
105
+ super(type: :type, **args)
108
106
  end
109
107
  end
110
108
  class Transfer < Action
111
- def initialize(args)
112
- super(args)
113
- self.type = "http://www.w3.org/ns/odrl/2/Action" unless self.type
109
+ def initialize(type: CACTION, **args)
110
+ super(type: :type, **args)
114
111
  end
115
112
  end
116
113
 
data/lib/odrl/asset.rb CHANGED
@@ -10,17 +10,15 @@ module ODRL
10
10
  class Asset < Base
11
11
  attr_accessor :uid, :hasPolicy, :refinements, :partOf
12
12
 
13
- def initialize(args)
14
- @uid = args[:uid]
13
+ def initialize(type: CASSET, hasPolicy: nil, refinements: nil, partOf: nil, **args)
14
+ @uid = uid
15
15
  unless @uid
16
16
  self.uid = Base.baseURI + "#asset_" + Base.getuuid
17
17
  end
18
- super(args.merge({uid: @uid}))
19
- self.type="http://www.w3.org/ns/odrl/2/Asset"
18
+ super(type: type, uid: @uid, **args)
20
19
 
21
- @refinements = Hash.new
22
- @partOf = args[:partOf]
23
- @hasPolicy = args[:hasPolicy]
20
+ @partOf = partOf
21
+ @hasPolicy = hasPolicy
24
22
 
25
23
  if @hasPolicy and !(@hasPolicy.is_a? Policy) # if it exists and is the wrong type
26
24
  raise "The policy of an Asset must be of type ODRL::Policy. The provided value will be discarded"
@@ -31,9 +29,10 @@ module ODRL
31
29
  @partOf = nil
32
30
  end
33
31
 
34
- args[:refinements] = [args[:refinements]] unless args[:refinements].is_a? Array
35
- if !(args[:refinements].first.nil?)
36
- args[:refinements].each do |c|
32
+ @refinements = Hash.new
33
+ refinements = [refinements] unless refinements.is_a? Array
34
+ if !(refinements.first.nil?)
35
+ refinements.each do |c|
37
36
  self.addRefinement(refinement: c)
38
37
  end
39
38
  end
@@ -82,9 +81,8 @@ module ODRL
82
81
 
83
82
  class AssetCollection < Asset
84
83
 
85
- def initialize(args)
86
- super(args)
87
- self.type="http://www.w3.org/ns/odrl/2/AssetCollection"
84
+ def initialize(type: CASSETCOLLECTION, **args)
85
+ super(type: type, **args)
88
86
  end
89
87
  end
90
88
 
data/lib/odrl/base.rb CHANGED
@@ -2,47 +2,52 @@
2
2
 
3
3
  require_relative "odrl/version"
4
4
 
5
- # one day move these all to ODRLV.xxxx
6
- CPOLICY= "http://www.w3.org/ns/odrl/2/Policy"
7
5
 
8
- CSET= "http://www.w3.org/ns/odrl/2/Set"
9
- COFFER= "http://www.w3.org/ns/odrl/2/Offer"
10
- CREQUEST= "http://www.w3.org/ns/odrl/2/Request"
11
- CAGREEMENT= "http://www.w3.org/ns/odrl/2/Agreement"
6
+ CPOLICY= ODRLV.Policy.to_s
12
7
 
13
- PASSET = "http://www.w3.org/ns/odrl/2/target"
14
- CASSET= "http://www.w3.org/ns/odrl/2/Asset"
8
+ CSET= ODRLV.Set.to_s
9
+ COFFER= ODRLV.Offer.to_s
10
+ CREQUEST= ODRLV.Request.to_s
11
+ CAGREEMENT= ODRLV.Agreement.to_s
12
+ CPRIVACY= ODRLV.Privacy.to_s
13
+ PASSET = ODRLV.target.to_s
14
+ CASSET= ODRLV.Asset.to_s
15
+ CASSETCOLLECTION= ODRLV.Asset.to_s
15
16
 
16
- CPERMISSION= "http://www.w3.org/ns/odrl/2/Permission"
17
- PPERMISSION = "http://www.w3.org/ns/odrl/2/permission"
18
- CPROHIBITION= "http://www.w3.org/ns/odrl/2/Prohibition"
19
- PPROHIBITION = "http://www.w3.org/ns/odrl/2/prohibition"
20
- PDUTY= "http://www.w3.org/ns/odrl/2/obligation"
21
- CDUTY = "http://www.w3.org/ns/odrl/2/Duty"
17
+ CRULE= ODRLV.Rule.to_s
18
+ CPERMISSION= ODRLV.Permission.to_s
19
+ PPERMISSION = ODRLV.permission.to_s
20
+ CPROHIBITION= ODRLV.Prohibition.to_s
21
+ PPROHIBITION = ODRLV.prohibition.to_s
22
+ PDUTY= ODRLV.obligation.to_s
23
+ CDUTY = ODRLV.Duty.to_s
22
24
 
23
- PRULE = "http://www.w3.org/ns/odrl/2/Rule"
25
+ PRULE = ODRLV.Rule.to_s
24
26
 
25
27
 
26
- PACTION = "http://www.w3.org/ns/odrl/2/action"
27
- CACTION= "http://www.w3.org/ns/odrl/2/Action"
28
+ PACTION = ODRLV.action.to_s
29
+ VUSE = ODRLV.use.to_s # this is goofy ODRL stuff...
30
+ VTRANSFER = ODRLV.transfer.to_s # this is goofy ODRL stuff...
31
+ CACTION= ODRLV.Action.to_s
28
32
 
29
- PREFINEMENT = "http://www.w3.org/ns/odrl/2/refinement"
33
+ PREFINEMENT = ODRLV.refinement.to_s
30
34
 
31
- PASSIGNER = "http://www.w3.org/ns/odrl/2/assigner"
32
- PASSIGNEE = "http://www.w3.org/ns/odrl/2/assignee"
33
- CPARTY= "http://www.w3.org/ns/odrl/2/Party"
35
+ PASSIGNER = ODRLV.assigner.to_s
36
+ PASSIGNEE = ODRLV.assignee.to_s
37
+ CPARTY= ODRLV.Party.to_s
38
+ CPARTYCOLLECTION= ODRLV.Party.to_s
34
39
 
35
- PCONSTRAINT = "http://www.w3.org/ns/odrl/2/constraint"
36
- CCONSTRAINT = "http://www.w3.org/ns/odrl/2/Constraint"
37
- PLEFT = "http://www.w3.org/ns/odrl/2/leftOperand"
38
- PRIGHT = "http://www.w3.org/ns/odrl/2/rightOperand"
39
- POPERATOR = "http://www.w3.org/ns/odrl/2/operator"
40
- POPERANDREFERENCE = "http://www.w3.org/ns/odrl/2/rightOperandReference"
41
- PDATATYPE = "http://www.w3.org/ns/odrl/2/dataType"
42
- PUNIT = "http://www.w3.org/ns/odrl/2/unit"
43
- PSTATUS = "http://www.w3.org/ns/odrl/2/status"
40
+ PCONSTRAINT = ODRLV.constraint.to_s
41
+ CCONSTRAINT = ODRLV.Constraint.to_s
42
+ PLEFT = ODRLV.leftOperand.to_s
43
+ PRIGHT = ODRLV.rightOperand.to_s
44
+ POPERATOR = ODRLV.operator.to_s
45
+ POPERANDREFERENCE = ODRLV.rightOperandReference.to_s
46
+ PDATATYPE = ODRLV.dataType.to_s
47
+ PUNIT = ODRLV.unit.to_s
48
+ PSTATUS = ODRLV.status.to_s
44
49
 
45
- PPARTOF = "http://www.w3.org/ns/odrl/2/partOf"
50
+ PPARTOF = ODRLV.partOf.to_s
46
51
 
47
52
 
48
53
  PROPERTIES = {
@@ -79,21 +84,31 @@ module ODRL
79
84
  return true
80
85
  end
81
86
 
82
- def initialize(args)
83
- #args = defaults.merge(args)
84
-
85
- @title = args[:title]
86
- @creator = args[:creator]
87
- @description = args[:description]
88
- @subject = args[:subject]
89
- @baseURI = args[:baseURI] || self.baseURI
90
- @uid = args[:uid]
91
- @type = args[:type]
92
- @label = args[:label] || @title
93
- @id = args[:uid] || nil
94
- #@repository = RDF::Repository.new() unless self.repository
87
+ def initialize(
88
+ title: nil,
89
+ creator: nil,
90
+ description: nil,
91
+ subject: nil,
92
+ baseURI: "http://example.org",
93
+ uid:,
94
+ id: nil,
95
+ type:,
96
+ label: nil,
97
+ **_)
98
+
99
+ @title = title
100
+ @creator = creator
101
+ @description = description
102
+ @subject = subject
103
+ @baseURI = baseURI || ODRL::Base.baseURI
104
+ @uid = uid
105
+ @type = type
106
+ @label = label || @title
107
+ @id = @uid
95
108
 
96
109
  raise "Every object must have a uid - attempt to create #{@type}" unless @uid
110
+ raise "Every object must have a type - " unless @type
111
+
97
112
 
98
113
  $g = RDF::Graph.new()
99
114
  if ENV["TRIPLES_FORMAT"]
@@ -101,23 +116,25 @@ module ODRL
101
116
  else
102
117
  $format = :jsonld
103
118
  end
104
- $writer = get_writer(type: $format) # set it by default
105
119
 
106
120
  end
107
121
 
108
122
  def get_writer(type:)
109
- $writer = RDF::Writer.for(type).buffer do |w|
110
- w.prefix(:foaf, RDF::URI.new("http://xmlns.com/foaf/0.1/"))
111
- w.prefix(:dc, RDF::URI.new("http://purl.org/dc/terms/"))
112
- w.prefix(:rdf, RDF::URI.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#"))
113
- w.prefix(:rdfs, RDF::URI.new("http://www.w3.org/2000/01/rdf-schema#"))
114
- w.prefix(:vcard, RDF::URI.new("http://www.w3.org/2006/vcard/ns#"))
115
- w.prefix(:odrl, RDF::URI.new("http://www.w3.org/ns/odrl/2/"))
116
- w.prefix(:this, RDF::URI.new("http://w3id.org/FAIR_Training_LDP/DAV/home/LDP/DUC-CCE/IPGB#"))
117
- w.prefix(:obo, RDF::URI.new("http://purl.obolibrary.org/obo/"))
118
- w.prefix(:xsd, RDF::URI.new("http://www.w3.org/2001/XMLSchema#"))
119
- end
120
- return $writer
123
+ w = RDF::Writer.for(type)
124
+ # w.prefix(:foaf, RDF::URI.new("http://xmlns.com/foaf/0.1/"))
125
+ # w.prefix(:dc, RDF::URI.new("http://purl.org/dc/terms/"))
126
+ # w.prefix(:rdf, RDF::URI.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#"))
127
+ # w.prefix(:rdfs, RDF::URI.new("http://www.w3.org/2000/01/rdf-schema#"))
128
+ # w.prefix(:vcard, RDF::URI.new("http://www.w3.org/2006/vcard/ns#"))
129
+ # w.prefix(:odrl, RDF::URI.new("http://www.w3.org/ns/odrl/2/"))
130
+ # w.prefix(:this, RDF::URI.new("http://w3id.org/FAIR_Training_LDP/DAV/home/LDP/DUC-CCE/IPGB#"))
131
+ # w.prefix(:obo, RDF::URI.new("http://purl.obolibrary.org/obo/"))
132
+ # w.prefix(:xsd, RDF::URI.new("http://www.w3.org/2001/XMLSchema#"))
133
+ # w.prefix(:orcid, RDF::URI.new("https://orcid.org/"))
134
+ # warn "W"
135
+ # warn w.prefixes.inspect
136
+
137
+ return w
121
138
  end
122
139
 
123
140
  def triplify(s, p, o, repo)
@@ -174,7 +191,7 @@ module ODRL
174
191
  end
175
192
 
176
193
  def load_graph
177
- [:title, :label, :creator, :description, :subject, :uid, :type].each do |method|
194
+ [:title, :label, :creator, :description, :subject, :uid, :id, :type].each do |method|
178
195
  next unless self.send(method)
179
196
  next if self.send(method).empty?
180
197
  subject = self.uid
@@ -188,7 +205,8 @@ module ODRL
188
205
 
189
206
  def serialize(format: $format)
190
207
  format = format.to_sym
191
- return self.repository.dump(format)
208
+ w = get_writer(type: format)
209
+ return w.dump(self.repository)
192
210
  end
193
211
 
194
212
  private
@@ -5,31 +5,40 @@ module ODRL
5
5
  class Constraint < Base
6
6
 
7
7
  attr_accessor :uid, :rightOperand, :leftOperand, :operator, :rightOperandReference, :dataType, :unit, :status
8
- def initialize(args)
9
- @uid = args[:uid]
8
+ def initialize(
9
+ uid: nil,
10
+ rightOperand:,
11
+ operator:,
12
+ leftOperand:,
13
+ rightOPerandReference: nil,
14
+ dataType: nil,
15
+ unit: nil,
16
+ status: nil,
17
+ type: CCONSTRAINT,
18
+ **args)
19
+
20
+ @uid = uid
10
21
  unless @uid
11
22
  @uid = Base.baseURI + "#constraint_" + Base.getuuid
12
23
  end
13
- super(args.merge({uid: @uid}))
14
-
15
- self.type = "http://www.w3.org/ns/odrl/2/Constraint"
24
+ super(uid: @uid, type: type, **args)
16
25
 
17
- @rightOperand = args[:rightOperand]
26
+ @rightOperand = rightOperand
18
27
  raise "Constraints must haves a Right operand such as 'event' - I'm dead!" unless @rightOperand
19
28
  @rightOperand = "http://www.w3.org/ns/odrl/2/#{@rightOperand}" unless @rightOperand =~ /https?:\/\// # if it is already a URI, then let it go
20
29
 
21
- @leftOperand = args[:leftOperand]
30
+ @leftOperand = leftOperand
22
31
  raise "Constraints must haves a Left Operand such as 'http://some.event.org/on-now' - I'm dead!" unless @leftOperand
23
32
  @leftOperand = "http://www.w3.org/ns/odrl/2/#{@leftOperand}" unless @leftOperand =~ /https?:\/\// # if it is already a URI, then let it go
24
33
 
25
- @operator = args[:operator]
34
+ @operator = operator
26
35
  raise "Constraints must haves an operator such as 'eq' - I'm dead!" unless @operator
27
36
  @operator = "http://www.w3.org/ns/odrl/2/#{@operator}" unless @operator =~ /https?:\/\// # if it is already a URI, then let it go
28
37
 
29
- @rightOperandReference = args[:rightOperandReference]
30
- @dataType = args[:dataType]
31
- @unit = args[:unit]
32
- @status = args[:status]
38
+ @rightOperandReference = rightOperandReference
39
+ @dataType = dataType
40
+ @unit = unit
41
+ @status = status
33
42
  end
34
43
 
35
44
  def load_graph
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ODRL
4
4
  module ODRL
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
data/lib/odrl/party.rb CHANGED
@@ -4,19 +4,25 @@ module ODRL
4
4
 
5
5
  class Party < Base
6
6
  attr_accessor :uid, :refinements, :partOf, :predicate, :type
7
- def initialize(args)
8
- @uid = args[:uid]
7
+ def initialize(
8
+ uid: nil,
9
+ refinements: nil,
10
+ partOf: nil,
11
+ predicate: nil,
12
+ type: CPARTY,
13
+ **args
14
+ )
15
+
16
+ @uid = uid
9
17
  unless @uid
10
18
  @uid = Base.baseURI + "#party_" + Base.getuuid
11
19
  end
12
- super(args.merge({uid: @uid}))
13
- self.type="http://www.w3.org/ns/odrl/2/Party"
20
+ super(uid: @uid, type: type, **args)
14
21
 
15
22
 
16
23
  @refinements = Hash.new
17
- @partOf = args[:partOf]
18
- @predicate = args[:predicate]
19
- @type = CPARTY
24
+ @partOf = partOf
25
+ @predicate = predicate
20
26
 
21
27
  unless @predicate
22
28
  raise "If you don't indicate a predicate (assigner/assignee) we will default to assigner. This may not be what you want!"
@@ -30,9 +36,9 @@ module ODRL
30
36
 
31
37
 
32
38
 
33
- args[:refinements] = [args[:refinements]] unless args[:refinements].is_a? Array
34
- if !(args[:refinements].first.nil?)
35
- args[:refinements].each do |c|
39
+ refinements = [refinements] unless refinements.is_a? Array
40
+ if !(refinements.first.nil?)
41
+ refinements.each do |c|
36
42
  self.addRefinement(refinement: c)
37
43
  end
38
44
  end
@@ -85,9 +91,8 @@ module ODRL
85
91
  end
86
92
  class PartyCollection < Party
87
93
 
88
- def initialize(args)
89
- super(args)
90
- self.type = "http://www.w3.org/ns/odrl/2/PartyCollection"
94
+ def initialize(type: CPARTYCOLLECTION, **args)
95
+ super(type: type, **args)
91
96
  end
92
97
  end
93
98
 
data/lib/odrl/policy.rb CHANGED
@@ -9,12 +9,12 @@ module ODRL
9
9
  class Policy < Base
10
10
  attr_accessor :rules
11
11
 
12
- def initialize(args)
13
- @uid = args[:uid]
12
+ def initialize(uid: nil, type: CPOLICY, **args)
13
+ @uid = uid
14
14
  unless @uid
15
15
  self.uid = Base.baseURI + "#policy_" + Base.getuuid
16
16
  end
17
- super(args.merge({uid: @uid}))
17
+ super(uid: @uid, type: type, **args)
18
18
 
19
19
  @rules = Hash.new
20
20
  end
@@ -53,24 +53,30 @@ module ODRL
53
53
  end
54
54
 
55
55
  class Set < Policy
56
- def initialize(args)
57
- super({type: CSET}.merge(args))
56
+ def initialize(type: CSET, **args)
57
+ super(type: type, **args)
58
58
  end
59
59
  end
60
60
 
61
61
  class Offer < Set
62
- def initialize(args)
63
- super({type: COFFER}.merge(args))
62
+ def initialize(type: COFFER, **args)
63
+ super(type: type, **args)
64
64
  end
65
65
  end
66
66
  class Agreement < Set
67
- def initialize(args)
68
- super({type: CAGREEMENT}.merge(args))
67
+ def initialize(type: CAGREEMENT, **args)
68
+ super(type: type, **args)
69
69
  end
70
70
  end
71
71
  class Request < Set
72
- def initialize(args)
73
- super({type: CREQUEST}.merge(args))
72
+ def initialize(type: CREQUEST, **args)
73
+ super(type: type, **args)
74
+ end
75
+ end
76
+
77
+ class Privacy < Set
78
+ def initialize(type: CPRIVACY, **args)
79
+ super(type: type, **args)
74
80
  end
75
81
  end
76
82
  # ====================================================
data/lib/odrl/rule.rb CHANGED
@@ -7,13 +7,22 @@ require_relative "odrl/version"
7
7
  module ODRL
8
8
  class Rule < Base
9
9
  attr_accessor :uid, :constraints, :assets, :predicate, :type, :action, :assigner, :assignee
10
- def initialize(args)
11
- @uid = args[:uid]
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
12
21
 
13
22
  unless @uid
14
23
  @uid = Base.baseURI + "#rule_" + Base.getuuid
15
24
  end
16
- super(args.merge({uid: @uid}))
25
+ super(uid: @uid, type: type, **args)
17
26
 
18
27
  @constraints = Hash.new
19
28
  @assets = Hash.new
@@ -21,15 +30,15 @@ module ODRL
21
30
  @assignee = Hash.new
22
31
  @action = Hash.new
23
32
 
24
- args[:assets] = [args[:assets]] unless args[:assets].is_a? Array
25
- if !(args[:assets].first.nil?)
26
- args[:assets].each do |c|
33
+ assets = [assets] unless assets.is_a? Array
34
+ if !assets.first.nil?
35
+ assets.each do |c|
27
36
  self.addAsset(asset: c)
28
37
  end
29
38
  end
30
- args[:constraints] = [args[:constraints]] unless args[:constraints].is_a? Array
31
- if !(args[:constraints].first.nil?)
32
- args[:constraints].each do |c|
39
+ constraints = [constraints] unless constraints.is_a? Array
40
+ if !constraints.first.nil?
41
+ constraints.each do |c|
33
42
  self.addConstraint(constraint: c)
34
43
  end
35
44
  end
@@ -99,32 +108,20 @@ module ODRL
99
108
 
100
109
 
101
110
  class Permission < Rule
102
- def initialize(args)
103
- super(args)
104
- self.predicate = PPERMISSION
105
- self.type = CPERMISSION
106
-
107
-
111
+ def initialize(predicate: PPERMISSION, type: CPERMISSION, **args)
112
+ super(predicate: predicate, type: type, **args)
108
113
  end
109
114
  end
110
115
 
111
116
  class Duty < Rule
112
- def initialize(args)
113
- super(args)
114
- self.predicate = PDUTY
115
- self.type = CDUTY
116
-
117
-
117
+ def initialize(predicate: PDUTY, type: CDUTY, **args)
118
+ super(predicate: predicate, type: type, **args)
118
119
  end
119
120
  end
120
121
 
121
122
  class Prohibition < Rule
122
- def initialize(args)
123
- super(args)
124
- self.predicate = PPROHIBITION
125
- self.type = CPROHIBITION
126
-
127
-
123
+ def initialize(predicate: PPROHIBITION, type: CPROHIBITION, **args)
124
+ super(predicate: predicate, type: type, **args)
128
125
  end
129
126
  end
130
127
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odrl-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
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-27 00:00:00.000000000 Z
11
+ date: 2023-06-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: builds ODRL files nicely.
14
14
  email:
@@ -47,6 +47,7 @@ metadata:
47
47
  homepage_uri: https://example.org
48
48
  source_code_uri: https://github.com/markwilkinson/ODRL-RUBY
49
49
  changelog_uri: https://github.com/markwilkinson/ODRL-RUBY/blob/master/CHANGELOG.md
50
+ documentation_uri: https://www.rubydoc.info/gems/odrl-ruby/
50
51
  post_install_message:
51
52
  rdoc_options: []
52
53
  require_paths: