Module: Intercom::HashableObject

Included in:
Event, Tag
Defined in:
lib/intercom/hashable_object.rb

Instance Method Summary collapse

Instance Method Details

#displayable_attributesObject



14
15
16
# File 'lib/intercom/hashable_object.rb', line 14

def displayable_attributes
  Hash[ to_hash.select {|attribute, value| self.respond_to?(attribute) } ]
end

#from_hash(hash) ⇒ Object



3
4
5
# File 'lib/intercom/hashable_object.rb', line 3

def from_hash(hash)
  hash.each {|attribute, value| instance_variable_set("@#{attribute}".to_sym, value) }
end

#to_hashObject



7
8
9
10
11
12
# File 'lib/intercom/hashable_object.rb', line 7

def to_hash
  instance_variables.inject({}) do |hash, var|
    hash[var.to_s.delete("@").to_sym] = instance_variable_get(var)
    hash
  end
end

#to_wireObject



18
19
20
# File 'lib/intercom/hashable_object.rb', line 18

def to_wire
  Hash[ to_hash.select {|attribute, value| self.respond_to?("#{attribute.to_s}=") } ]
end