Class: JSONAPI::HeaderCollection

Inherits:
NameValuePairCollection show all
Defined in:
lib/easy/jsonapi/header_collection.rb,
lib/easy/jsonapi/header_collection/header.rb

Overview

header_collection # { include: Include, sort: Sort, filter: Filter }

Defined Under Namespace

Classes: Header

Instance Method Summary collapse

Methods inherited from NameValuePairCollection

#<<, #to_h, #to_s

Methods inherited from Collection

#[], #[]=, #each, #empty?, #include?, #insert, #keys, #remove, #set, #size, #to_s

Constructor Details

#initialize(header_arr = []) ⇒ Object

Initialize as empty if a array of Header objects not passed to it.

Parameters:



13
14
15
# File 'lib/easy/jsonapi/header_collection.rb', line 13

def initialize(header_arr = [])
  super(header_arr, item_type: JSONAPI::HeaderCollection::Header)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JSONAPI::NameValuePairCollection

Instance Method Details

#add(header) ⇒ Object

Add a header to the collection. (CASE-INSENSITIVE).

Parameters:



19
20
21
# File 'lib/easy/jsonapi/header_collection.rb', line 19

def add(header)
  super(header) { |hdr| hdr.name.downcase.gsub(/-/, '_') }
end

#get(key) ⇒ Object

Call super’s get but make it case insensitive

Parameters:

  • key (Symbol)

    The hash key associated with a header



25
26
27
# File 'lib/easy/jsonapi/header_collection.rb', line 25

def get(key)
  super(key.to_s.downcase.gsub(/-/, '_'))
end