Method: Twitter::ModelMixin::ClassMethods#unmarshal

Defined in:
lib/vendor/twitter/lib/twitter/model.rb

#unmarshal(raw) ⇒ Object

Unmarshal object singular or plural array of model objects from JSON serialization. Currently JSON is only supported since this is all Twitter4R needs.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 32

def unmarshal(raw)
  input = JSON.parse(raw)
  def unmarshal_model(hash)
    self.new(hash)
  end
  return unmarshal_model(input) if input.is_a?(Hash) # singular case
  result = []
  input.each do |hash|
    model = unmarshal_model(hash) if hash.is_a?(Hash)
    result << model
  end if input.is_a?(Array)
  result # plural case
end