Class: RedSnow::KeyValueCollection Abstract

Inherits:
BlueprintNode show all
Defined in:
lib/redsnow/blueprint.rb

Overview

This class is abstract.

Blueprint AST node for key-value collections

Direct Known Subclasses

Headers, Metadata

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#collectionArray<Hash>

array of key value hashes

Returns:

  • (Array<Hash>)

    the current value of collection



58
59
60
# File 'lib/redsnow/blueprint.rb', line 58

def collection
  @collection
end

Instance Method Details

#[](key) ⇒ NilClass, String

Retrieves the value of the collection item by its key

Parameters:

  • key (String)

    Name of the item key to retrieve

Returns:

  • (NilClass)

    if the collection does not have an item with the key

  • (String)

    if the collection has an item with the key



67
68
69
70
# File 'lib/redsnow/blueprint.rb', line 67

def [] key
  return nil if @collection.nil?
  return_item_value key
end

#filter_collection(ignore_keys) ⇒ Array<Hash>

Filter collection keys

Returns:

  • (Array<Hash>)

    collection without ignored keys



74
75
76
77
# File 'lib/redsnow/blueprint.rb', line 74

def filter_collection(ignore_keys)
  return @collection if ignore_keys.blank?
  @collection.select { |kv_item| !ignore_keys.include?(kv_item.keys.first) }
end