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



55
56
57
# File 'lib/redsnow/blueprint.rb', line 55

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



63
64
65
66
# File 'lib/redsnow/blueprint.rb', line 63

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



70
71
72
73
# File 'lib/redsnow/blueprint.rb', line 70

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