class JSONAPI::NameValuePair
A generic name->value query pair
Public Class Methods
new(name, value)
click to toggle source
@param name The name of the pair @param value The value of the pair
Calls superclass method
JSONAPI::Item::new
# File lib/easy/jsonapi/name_value_pair.rb, line 12 def initialize(name, value) name = name.to_s.gsub('-', '_') super({ name: name.to_s, value: value }) end
Public Instance Methods
name()
click to toggle source
@return [String] The name of the name->val pair
# File lib/easy/jsonapi/name_value_pair.rb, line 18 def name @item[:name] end
name=(_)
click to toggle source
@raise RunTimeError You shouldn't be able to update the name of a
NameValuePair
# File lib/easy/jsonapi/name_value_pair.rb, line 24 def name=(_) raise 'Cannot change the name of NameValuePair Objects' end
to_h()
click to toggle source
Represents a pair as a hash
# File lib/easy/jsonapi/name_value_pair.rb, line 65 def to_h { name.to_sym => JSONAPI::Utility.to_h_value(value) } end
to_s()
click to toggle source
Represents a pair as a string
# File lib/easy/jsonapi/name_value_pair.rb, line 39 def to_s v = value val_str = case v when Array val_str = '[' first = true v.each do |val| if first val_str += "\"#{val}\"" first = false else val_str += ", \"#{val}\"" end end val_str += ']' when String "\"#{v}\"" when JSONAPI::NameValuePair "{ #{v} }" else v end "\"#{name}\": #{val_str}" end
value()
click to toggle source
@return [String] The value of the name->val pair
# File lib/easy/jsonapi/name_value_pair.rb, line 29 def value @item[:value] end
value=(new_value)
click to toggle source
@param new_value [String | Symbol] The name->val pair value
# File lib/easy/jsonapi/name_value_pair.rb, line 34 def value=(new_value) @item[:value] = new_value end