Module: Twitter::ModelMixin::ClassMethods

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

Overview

Class methods defined for Twitter::ModelMixin module.

Instance Method Summary collapse

Instance Method Details

#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

#unmarshal_model(hash) ⇒ Object



34
35
36
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 34

def unmarshal_model(hash)
  self.new(hash)
end