Class: OpenSocial::Group

Inherits:
Base
  • Object
show all
Defined in:
lib/opensocial/group.rb

Overview

Acts as a wrapper for an OpenSocial group.

The Group class takes input JSON as an initialization parameter, and iterates through each of the key/value pairs of that JSON. For each key that is found, an attr_accessor is constructed, allowing direct access to the value. Each value is stored in the attr_accessor, either as a String, Fixnum, Hash, or Array.

Instance Method Summary collapse

Methods inherited from Base

#add_attr

Constructor Details

#initialize(json) ⇒ Group

Initializes the Group based on the provided json fragment. If no JSON is provided, an empty object (with no attributes) is created.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/opensocial/group.rb', line 30

def initialize(json)
  if json
    json.each do |key, value|
      proper_key = key.underscore
      begin
        self.send("#{proper_key}=", value)
      rescue NoMethodError
        add_attr(proper_key)
        self.send("#{proper_key}=", value)
      end
    end
  end
end