Class: Aspire::Enumerator::LinkedDataURIEnumerator

Inherits:
JSONEnumerator show all
Defined in:
lib/aspire/enumerator/linked_data_uri_enumerator.rb

Overview

Enumerates the URI properties of a linked data API object

Instance Attribute Summary

Attributes inherited from JSONEnumerator

#hooks, #yielder

Instance Method Summary collapse

Methods inherited from JSONEnumerator

#[], #[]=, #array, #enumerate, #enumerator, #hash, #property

Constructor Details

#initialize(yielder = nil, **hooks) {|key, hash, index| ... } ⇒ LinkedDataURIEnumerator

Initialises a new LinkedDataAPIEnumerator instance

Parameters:

  • yielder (Enumerator::Yielder) (defaults to: nil)

    the yielder from an Enumerator

  • hooks (Hash)

    the callback hooks

Yields:

  • (key, hash, index)

    passes each hash to the block

Yield Parameters:

  • key (Object)

    the hash property name

  • hash (Hash)

    the hash

  • index (Integer, nil)

    the index of the hash in its parent array, or nil if not part of an array



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/aspire/enumerator/linked_data_uri_enumerator.rb', line 16

def initialize(yielder = nil, **hooks)
  super(yielder, **hooks)
  # Yield only hashes { type: "uri", value: "..." }
  self[:before_hash] = proc do |key, hash, index|
    if hash['type'] == 'uri' && hash['value'] && !hash['value'].empty?
      self.yielder << [key, hash, index]
      false
    else
      true
    end
  end
  # Do not yield properties
  self[:before_yield] = proc { |_key, _value, _index| false }
end