class JSONAPI::NameValuePairCollection

Collection of Items that all have names and values.

Public Class Methods

new(pair_arr = [], item_type: JSONAPI::NameValuePair, &block) click to toggle source

Creates an empty collection by default @param pair_arr [Array<JSONAPI::NameValuePair>] The pairs to be initialized with.

Calls superclass method JSONAPI::Collection::new
# File lib/easy/jsonapi/name_value_pair_collection.rb, line 14
def initialize(pair_arr = [], item_type: JSONAPI::NameValuePair, &block)
  if block_given?
    super(pair_arr, item_type: item_type, &block)
  else
    super(pair_arr, item_type: item_type, &:name)
  end
end

Public Instance Methods

<<(pair, &block) click to toggle source

Another way to add a query_param @oaram (see add)

# File lib/easy/jsonapi/name_value_pair_collection.rb, line 37
def <<(pair, &block)
  add(pair, &block)
end
add(pair, &block) click to toggle source

Add a pair to the collection. (CASE-SENSITIVE) @param pair [JSONAPI::NameValuePair] The pair to add

Calls superclass method JSONAPI::Collection#add
# File lib/easy/jsonapi/name_value_pair_collection.rb, line 27
def add(pair, &block)
  if block_given?
    super(pair, &block)
  else
    super(pair, &:name)
  end
end
to_h() click to toggle source

Represent the collection as a hash @return [Hash] The representation of the collection

# File lib/easy/jsonapi/name_value_pair_collection.rb, line 55
def to_h
  JSONAPI::Utility.to_h_collection(self)
end
to_s() click to toggle source

Represent the collection as a string @return [String] The representation of the collection

# File lib/easy/jsonapi/name_value_pair_collection.rb, line 49
def to_s
  JSONAPI::Utility.to_string_collection(self, pre_string: '{ ', post_string: ' }')
end

Private Instance Methods

method_missing(method_name, *args, &block) click to toggle source

Gets the NameValuePair object value whose name matches the method_name called @param method_name [Symbol] The name of the method called @param args If any arguments were passed to the method called @param block If a block was passed to the method called

Calls superclass method JSONAPI::Collection#method_missing
# File lib/easy/jsonapi/name_value_pair_collection.rb, line 67
def method_missing(method_name, *args, &block)
  super unless include?(method_name)
  get(method_name).value
end
respond_to_missing?(method_name, *) click to toggle source

Whether or not method missing should be called.

Calls superclass method JSONAPI::Collection#respond_to_missing?
# File lib/easy/jsonapi/name_value_pair_collection.rb, line 73
def respond_to_missing?(method_name, *)
  include?(method_name) || super
end