class DTK::Client::HashWithOptionalKeys

Public Class Methods

new(raw={}) click to toggle source
Calls superclass method
# File lib/client/util/hash_with_optional_keys.rb, line 20
def initialize(raw={})
  super()
  replace(convert(raw)) unless raw.empty?
end

Public Instance Methods

merge(raw) click to toggle source
Calls superclass method
# File lib/client/util/hash_with_optional_keys.rb, line 25
def merge(raw)
  super(convert(raw))
end
merge!(raw) click to toggle source
Calls superclass method
# File lib/client/util/hash_with_optional_keys.rb, line 29
def merge!(raw)
  super(convert(raw))
end

Private Instance Methods

convert(raw) click to toggle source
# File lib/client/util/hash_with_optional_keys.rb, line 35
def convert(raw)
  raw.inject(Hash.new) do |h,(k,v)|
    if non_null_var = is_only_non_null_var?(k)
      v.nil? ? h : h.merge(non_null_var => v)
    else
      h.merge(k => v)
    end
  end
end
is_only_non_null_var?(k) click to toggle source
# File lib/client/util/hash_with_optional_keys.rb, line 45
def is_only_non_null_var?(k)
  if k.to_s =~ /\?$/
    k.to_s.gsub(/\?$/,'').to_sym
  end
end