Class: OpenSocial::AppData
Overview
Acts as a wrapper for an OpenSocial appdata entry.
The AppData class takes a person’s ID and input JSON as initialization parameters, and iterates through each of the key/value pairs of that JSON. For each key that is found, an attr_accessor is constructed (except for :id which is preconstructed, and required), allowing direct access to the value. Each value is stored in the attr_accessor, either as a String, Fixnum, Hash, or Array.
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
-
#initialize(id, json) ⇒ AppData
constructor
Initializes the AppData entry based on the provided id and json fragment.
Methods inherited from Base
Constructor Details
#initialize(id, json) ⇒ AppData
Initializes the AppData entry based on the provided id and json fragment. If no JSON is provided, an empty object (with only an ID) is created.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/opensocial/appdata.rb', line 32 def initialize(id, json) @id = id if json json.each do |key, value| begin self.send("#{key}=", value) rescue NoMethodError add_attr(key) self.send("#{key}=", value) end end end end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
28 29 30 |
# File 'lib/opensocial/appdata.rb', line 28 def id @id end |