Class: Coarnotify::Core::Notify::NotifyObject

Inherits:
NotifyPatternPart show all
Defined in:
lib/coarnotify/core/notify.rb

Overview

Default class to represent an object in the COAR Notify pattern. Objects can be used for object or context properties in notify patterns

Specific patterns may need to extend this class to provide their specific behaviours and validation

Instance Attribute Summary

Attributes inherited from NotifyBase

#properties_by_reference, #validate_properties, #validate_stream_on_construct, #validators

Instance Method Summary collapse

Methods inherited from NotifyPatternPart

#allowed_types, allowed_types, default_type, #initialize, #type=

Methods inherited from NotifyBase

#doc, #get_property, #id, #id=, #initialize, #optional_and_validate, #register_property_validation_error, #required, #required_and_validate, #set_property, #to_jsonld, #type, #type=, #validate_property

Constructor Details

This class inherits a constructor from Coarnotify::Core::Notify::NotifyPatternPart

Instance Method Details

#cite_asString

Get the ietf:cite-as property of the object

Returns:

  • (String)

    the cite-as value



631
632
633
# File 'lib/coarnotify/core/notify.rb', line 631

def cite_as
  get_property(NotifyProperties::CITE_AS)
end

#cite_as=(value) ⇒ Object

Set the ietf:cite-as property of the object

Parameters:

  • value (String)

    the cite-as value to set



638
639
640
# File 'lib/coarnotify/core/notify.rb', line 638

def cite_as=(value)
  set_property(NotifyProperties::CITE_AS, value)
end

#itemNotifyItem?

Get the ietf:item property of the object

Returns:



645
646
647
648
649
650
651
652
653
# File 'lib/coarnotify/core/notify.rb', line 645

def item
  i = get_property(NotifyProperties::ITEM)
  if i
    NotifyItem.new(stream: i, validate_stream_on_construct: false,
                   validate_properties: @validate_properties, validators: @validators,
                   validation_context: NotifyProperties::ITEM,
                   properties_by_reference: @properties_by_reference)
  end
end

#item=(value) ⇒ Object

Set the ietf:item property of the object

Parameters:



658
659
660
# File 'lib/coarnotify/core/notify.rb', line 658

def item=(value)
  set_property(NotifyProperties::ITEM, value)
end

#tripleArray<String>

Get object, relationship and subject properties as a relationship triple

Returns:

  • (Array<String>)

    array of [object, relationship, subject]



665
666
667
668
669
670
# File 'lib/coarnotify/core/notify.rb', line 665

def triple
  obj = get_property(ActivityStreams2::Properties::OBJECT_TRIPLE)
  rel = get_property(ActivityStreams2::Properties::RELATIONSHIP_TRIPLE)
  subj = get_property(ActivityStreams2::Properties::SUBJECT_TRIPLE)
  [obj, rel, subj]
end

#triple=(value) ⇒ Object

Set object, relationship and subject properties as a relationship triple

Parameters:

  • value (Array<String>)

    array of [object, relationship, subject]



675
676
677
678
679
680
# File 'lib/coarnotify/core/notify.rb', line 675

def triple=(value)
  obj, rel, subj = value
  set_property(ActivityStreams2::Properties::OBJECT_TRIPLE, obj)
  set_property(ActivityStreams2::Properties::RELATIONSHIP_TRIPLE, rel)
  set_property(ActivityStreams2::Properties::SUBJECT_TRIPLE, subj)
end

#validateBoolean

Validate the object. This overrides the base validation, as objects only absolutely require an id property, so the base requirement for a type is relaxed.

Returns:

  • (Boolean)

    true if valid, otherwise raises ValidationError



686
687
688
689
690
691
692
693
# File 'lib/coarnotify/core/notify.rb', line 686

def validate
  ve = ValidationError.new

  required_and_validate(ve, ActivityStreams2::Properties::ID, id)

  raise ve if ve.has_errors?
  true
end