Sha256: 7c24b2a8cb28cf98b021fb0e19b11c6bf879e06d801ee7e6dc689832ad445f43

Contents?: true

Size: 576 Bytes

Versions: 14

Compression:

Stored size: 576 Bytes

Contents

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

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

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

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
intercom-1.0.0 lib/intercom/hashable_object.rb
intercom-0.3.0 lib/intercom/hashable_object.rb
intercom-0.2.3 lib/intercom/hashable_object.rb
intercom-0.2.2 lib/intercom/hashable_object.rb
intercom-0.2.1 lib/intercom/hashable_object.rb
intercom-0.2.0 lib/intercom/hashable_object.rb
intercom-0.1.19 lib/intercom/hashable_object.rb
intercom-0.1.17 lib/intercom/hashable_object.rb
intercom-0.1.16 lib/intercom/hashable_object.rb
intercom-0.1.15 lib/intercom/hashable_object.rb
intercom-0.1.14 lib/intercom/hashable_object.rb
intercom-0.1.13 lib/intercom/hashable_object.rb
intercom-0.1.12 lib/intercom/hashable_object.rb
intercom-0.1.11 lib/intercom/hashable_object.rb