Permalink
Browse files

Event improvements. Actual attributes, helpers to determine type (ie …

…text?), and added =~ operator.
  • Loading branch information...
1 parent 1433173 commit 85d5b9bb4a77f01af8910f2c81aeaa4dfa88c69f @technicalpickles technicalpickles committed Sep 6, 2011
Showing with 21 additions and 0 deletions.
  1. +21 −0 lib/firetower/event.rb
View
@@ -2,13 +2,17 @@ module Firetower
class Event
attr_accessor :attributes
attr_accessor :room
+ attr_accessor :created_at, :body, :id, :user_id, :type
def self.parse(json)
new(JSON.parse(json))
end
def initialize(attributes)
@attributes = attributes
+ @attributes.each do |key, value|
+ send("#{key}=", value) if respond_to?("#{key}=")
+ end
end
def [](key)
@@ -18,5 +22,22 @@ def [](key)
def []=(key, value)
@attributes[key] = value
end
+
+ def text?
+ self.type == 'TextMessage'
+ end
+
+ def sound?
+ self.type == 'SoundMessage'
+ end
+
+ def timestamp?
+ self.type == 'TimestampMessage'
+ end
+
+ def =~(pattern)
+ self.body =~ pattern
+ end
+
end
end

0 comments on commit 85d5b9b

Please sign in to comment.