Class: Dam::Activity

Inherits:
Object
  • Object
show all
Defined in:
lib/dam/activity.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, params = {}) ⇒ Activity

Returns a new instance of Activity.



87
88
89
90
# File 'lib/dam/activity.rb', line 87

def initialize(type, params = {})
  @attributes = params
  @type = type
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)



112
113
114
115
116
117
118
# File 'lib/dam/activity.rb', line 112

def method_missing(meth, *args, &block)
  if @attributes.has_key? meth.to_s
    @attributes[meth.to_s]
  else
    super
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



86
87
88
# File 'lib/dam/activity.rb', line 86

def attributes
  @attributes
end

Class Method Details

.[](name) ⇒ Object



82
83
84
# File 'lib/dam/activity.rb', line 82

def self.[](name)
  Dam::ActivityType.lookup(name)
end

.from_json(json) ⇒ Object



100
101
102
103
104
# File 'lib/dam/activity.rb', line 100

def self.from_json json
  attributes = Yajl::Parser.parse(json)
  type = attributes.delete("_type").to_sym
  new(type, attributes)
end

Instance Method Details

#==(other) ⇒ Object



92
93
94
# File 'lib/dam/activity.rb', line 92

def ==(other)
  @type == other.instance_variable_get("@type") && attributes == other.attributes
end

#post!Object



96
97
98
# File 'lib/dam/activity.rb', line 96

def post!
  Dam.push(self)
end

#to_jsonObject



106
107
108
# File 'lib/dam/activity.rb', line 106

def to_json
  Yajl::Encoder.encode(self.attributes.merge({:_type => @type}))
end