Class: ODRL::Action

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

Overview

ODRL::Action Describes an action like “use”

Author:

  • Mark D Wilkinson

Direct Known Subclasses

Transfer, Use

Instance Attribute Summary collapse

Attributes inherited from Base

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

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(value:, vallabel: "", type: CACTION, **args) ⇒ Action

constructor

Parameters:

  • opts (Hash)

    the options to create a message with.



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/action.rb', line 21

def initialize(value:, vallabel: "", type: CACTION, **args)
  @value = value
  @vallabel = vallabel || @value
  raise "Actions must haves a value such as 'use' - I'm dead!" unless @value

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

  @uid = @value
  # unless @uid
  #     self.uid = Base.baseURI + "#action_" + Base.getuuid
  # end
  super(uid: @uid, type: type, **args)

  @refinements = {}

  args[:refinements] = [args[:refinements]] unless args[:refinements].is_a? Array
  unless args[:refinements].first.nil?
    args[:refinements].each do |c|
      addRefinement(refinement: c)
    end
  end

  self.predicate = PACTION unless predicate
end

Instance Attribute Details

#(optional)URI

uid the URI of the Action node

Returns:

  • (URI)

    the current value of (optional)



13
14
15
# File 'lib/odrl/action.rb', line 13

def (optional)
  @(optional)
end

#predicateURI

(optional) the predicate you wish to use with this action

Returns:

  • (URI)

    the current value of predicate



13
14
15
# File 'lib/odrl/action.rb', line 13

def predicate
  @predicate
end

#refinementsObject

Returns the value of attribute refinements.



14
15
16
# File 'lib/odrl/action.rb', line 14

def refinements
  @refinements
end

#typeObject

Returns the value of attribute type.



14
15
16
# File 'lib/odrl/action.rb', line 14

def type
  @type
end

#uidObject

Returns the value of attribute uid.



14
15
16
# File 'lib/odrl/action.rb', line 14

def uid
  @uid
end

#vallabelstring

(optional) a string like “use”

Returns:

  • (string)

    the current value of vallabel



13
14
15
# File 'lib/odrl/action.rb', line 13

def vallabel
  @vallabel
end

#valuestring

(required) a string like “use”

Returns:

  • (string)

    the current value of value



13
14
15
# File 'lib/odrl/action.rb', line 13

def value
  @value
end

Instance Method Details

#addRefinement(refinement: args) ⇒ Object

Adds an ODRL Refinement

Parameters:

  • refinement (ODRL::Refinement) (defaults to: args)

    the refinement to the action



51
52
53
54
55
# File 'lib/odrl/action.rb', line 51

def addRefinement(refinement: args)
  raise "Refinement is not an ODRL Constraint" unless refinement.is_a?(Constraint)

  refinements[refinement.uid] = [PREFINEMENT, refinement]
end

#load_graphObject

Causes the triples of this object to be formed in the in-memory store This includes any “cascading” objects for which this is the subject of the triple



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

def load_graph
  super
  # TODO: This is bad DRY!!  Put the bulk of this method into the base object
  [: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
  subject = uid
  object = vallabel
  predicate = SCHEMA.name
  repo = repository
  triplify(subject, predicate, object, repo)
  object = vallabel
  predicate = RDFS.label
  repo = repository
  triplify(subject, predicate, object, repo)
end

#serialize(format:) ⇒ Object

Returns the serialized RDF for this object and cascading related objects

Parameters:

  • format (Symbol)

    a valid RDF::Writer format (e.g. :turtle)



90
91
92
# File 'lib/odrl/action.rb', line 90

def serialize(format:)
  super
end