Class: ODRL::Constraint

Inherits:
Base
  • Object
show all
Defined in:
lib/odrl/constraint.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#baseURI, #creator, #description, #id, #issued, #label, #subject, #title, #type

Instance Method Summary collapse

Methods inherited from Base

baseURI, clear_repository, #get_writer, getuuid, repository, #repository, #triplify

Constructor Details

#initialize(rightOperand:, operator:, leftOperand:, uid: nil, rightOPerandReference: nil, dataType: nil, unit: nil, status: nil, type: CCONSTRAINT, **args) ⇒ Constraint

Returns a new instance of Constraint.



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
# File 'lib/odrl/constraint.rb', line 7

def initialize(
  rightOperand:, operator:, leftOperand:, uid: nil,
  rightOPerandReference: nil,
  dataType: nil,
  unit: nil,
  status: nil,
  type: CCONSTRAINT,
  **args
)

  @uid = uid
  @uid ||= Base.baseURI + "#constraint_" + Base.getuuid
  super(uid: @uid, type: type, **args)

  @rightOperand = rightOperand
  raise "Constraints must haves a Right operand such as 'event' - I'm dead!" unless @rightOperand

  # if it is already a URI, then let it go
  # @rightOperand = "http://www.w3.org/ns/odrl/2/#{@rightOperand}" unless @rightOperand =~ %r{https?://}

  @leftOperand = leftOperand
  unless LEFTOPERANDS.include?(@leftOperand)
    warn "The selected leftOperand is not part of the default set... just sayin'"
  end
  unless @leftOperand
    raise "Constraints must haves a Left Operand such as 'http://some.event.org/on-now' - I'm dead!"
  end

  # if it is already a URI, then let it go
  @leftOperand = "http://www.w3.org/ns/odrl/2/#{@leftOperand}" unless @leftOperand =~ %r{https?://}

  @operator = operator
  raise "Constraints must haves an operator such as 'eq' - I'm dead!" unless @operator

  warn "The selected operator is not part of the default set... just sayin'" unless OPERATORS.include?(@operator)

  # if it is already a URI, then let it go
  @operator = "http://www.w3.org/ns/odrl/2/#{@operator}" unless @operator =~ %r{https?://}

  @rightOperandReference = rightOperandReference
  @dataType = dataType
  @unit = unit
  @status = status
end

Instance Attribute Details

#dataTypeObject

Returns the value of attribute dataType.



5
6
7
# File 'lib/odrl/constraint.rb', line 5

def dataType
  @dataType
end

#leftOperandObject

Returns the value of attribute leftOperand.



5
6
7
# File 'lib/odrl/constraint.rb', line 5

def leftOperand
  @leftOperand
end

#operatorObject

Returns the value of attribute operator.



5
6
7
# File 'lib/odrl/constraint.rb', line 5

def operator
  @operator
end

#rightOperandObject

Returns the value of attribute rightOperand.



5
6
7
# File 'lib/odrl/constraint.rb', line 5

def rightOperand
  @rightOperand
end

#rightOperandReferenceObject

Returns the value of attribute rightOperandReference.



5
6
7
# File 'lib/odrl/constraint.rb', line 5

def rightOperandReference
  @rightOperandReference
end

#statusObject

Returns the value of attribute status.



5
6
7
# File 'lib/odrl/constraint.rb', line 5

def status
  @status
end

#uidObject

Returns the value of attribute uid.



5
6
7
# File 'lib/odrl/constraint.rb', line 5

def uid
  @uid
end

#unitObject

Returns the value of attribute unit.



5
6
7
# File 'lib/odrl/constraint.rb', line 5

def unit
  @unit
end

Instance Method Details

#load_graphObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/odrl/constraint.rb', line 52

def load_graph
  super
  # TODO: This is bad DRY!!  Put the bulk of this method into the base object
  if rightOperand
    predicate = PRIGHT
    object = rightOperand
    subject = uid
    repo = repository
    triplify(subject, predicate, object, repo)
  end
  if leftOperand
    predicate = PLEFT
    object = leftOperand
    subject = uid
    repo = repository
    triplify(subject, predicate, object, repo)
  end
  if operator
    predicate = POPERATOR
    object = operator
    subject = uid
    repo = repository
    triplify(subject, predicate, object, repo)
  end
  if rightOperandReference
    predicate = POPERANDREFERENCE
    object = rightOperandReference
    subject = uid
    repo = repository
    triplify(subject, predicate, object, repo)
  end
  if dataType
    predicate = PDATATYPE
    object = dataType
    subject = uid
    repo = repository
    triplify(subject, predicate, object, repo)
  end
  if unit
    predicate = PUNIT
    object = unit
    subject = uid
    repo = repository
    triplify(subject, predicate, object, repo)
  end
  return unless status

  predicate = PSTATUS
  object = status
  subject = uid
  repo = repository
  triplify(subject, predicate, object, repo)
end

#serialize(format:) ⇒ Object



106
107
108
# File 'lib/odrl/constraint.rb', line 106

def serialize(format:)
  super
end