class JSONAPI::NameValuePairCollection
Collection
of Items that all have names and values.
Public Class Methods
Creates an empty collection by default @param pair_arr [Array<JSONAPI::NameValuePair>] The pairs to be initialized with.
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
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 a pair to the collection. (CASE-SENSITIVE) @param pair [JSONAPI::NameValuePair] The pair to add
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
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
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
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
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
Whether or not method missing should be called.
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