Module: Parliament::Grom::Decorator::Collection

Defined in:
lib/parliament/grom/decorator/collection.rb

Overview

Decorator namespace for Grom::Node instances with type: example.com/content/Collection Collection Grom::Node is a Contentful object associated with a web article (a WebArticle has an Audience node) Collection Grom::Node is not modelled in the data service, hence type ‘example..’ and not ‘id.parliament.uk/schema

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#articlesArray

Alias collectionHasArticle with fallback.

Returns:

  • (Array, Array)

    an array of Articles related to the Grom::Node or an empty Array.

Since:

  • 0.1.0



32
33
34
# File 'lib/parliament/grom/decorator/collection.rb', line 32

def articles
  respond_to?(:collectionHasArticle) ? collectionHasArticle : []
end

#descriptionString

Alias collectionDescription with fallback.

Returns:

  • (String, String)

    the description of the Grom::Node or an empty string.

Since:

  • 0.1.0



18
19
20
# File 'lib/parliament/grom/decorator/collection.rb', line 18

def description
  respond_to?(:collectionDescription) ? collectionDescription : ''
end

#extended_descriptionString

Alias collectionExtendedDescription with fallback.

Returns:

  • (String, String)

    the extended description of the Grom::Node or an empty string.

Since:

  • 0.1.0



25
26
27
# File 'lib/parliament/grom/decorator/collection.rb', line 25

def extended_description
  respond_to?(:collectionExtendedDescription) ? collectionExtendedDescription : ''
end

#nameString

Alias collectionName with fallback.

Returns:

  • (String, String)

    the name of the Grom::Node or an empty string.

Since:

  • 0.1.0



11
12
13
# File 'lib/parliament/grom/decorator/collection.rb', line 11

def name
  respond_to?(:collectionName) ? collectionName : ''
end

#orphaned_ancestors(nodes = parents) ⇒ Array

Travel up the ancestry trees finding orphaned collections

Returns:

  • (Array, Array)

    an array of orphaned ancestral collections related to the Grom::Node or an empty Array.

Since:

  • 0.1.0



53
54
55
56
57
58
# File 'lib/parliament/grom/decorator/collection.rb', line 53

def orphaned_ancestors(nodes = parents)
  orphans = nodes.select { |node| node.parents.none? }
  parent_nodes = (nodes - orphans).map(&:parents).flatten
  orphans += orphaned_ancestors(parent_nodes) if parent_nodes.any?
  orphans
end

#parentsArray

Alias collectionHasParent with fallback.

Returns:

  • (Array, Array)

    an array of parent collections related to the Grom::Node or an empty Array.

Since:

  • 0.1.0



46
47
48
# File 'lib/parliament/grom/decorator/collection.rb', line 46

def parents
  respond_to?(:collectionHasParent) ? collectionHasParent : []
end

#subcollectionsArray

Alias collectionHasSubcollection with fallback.

Returns:

  • (Array, Array)

    an array of Subcollections related to the Grom::Node or an empty Array.

Since:

  • 0.1.0



39
40
41
# File 'lib/parliament/grom/decorator/collection.rb', line 39

def subcollections
  respond_to?(:collectionHasSubcollection) ? collectionHasSubcollection : []
end