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



44
45
46
# File 'lib/redsnow/blueprint.rb', line 44

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



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

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



60
61
62
63
# File 'lib/redsnow/blueprint.rb', line 60

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