Class: Hash

Inherits:
Object show all
Defined in:
lib/user_input.rb

Instance Method Summary collapse

Instance Method Details

#from_user_input(value) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/user_input.rb', line 166

def from_user_input(value)
  if (self.length != 1)
    raise ArgumentError, "Must supply only one element to a hash you're calling from_user_input on."
  end
  if (!value.kind_of?(Hash))
    return nil
  end
  keytype = nil
  valtype = nil
  self.each {|k,v| keytype = k; valtype = v}
  output = {}
  value.each {|k, v|
    if (!(k = keytype.from_user_input(k)).nil? && !(v = valtype.from_user_input(v)).nil?)
      output[k] = v
    end
  }
  if (output.length > 0)
    return output
  else
    return nil
  end
end