Module: Esendex::HashSerialisation
- Included in:
- InboundMessage, MessageDeliveredEvent, MessageFailedEvent
- Defined in:
- lib/esendex/hash_serialisation.rb
Instance Method Summary collapse
Instance Method Details
#initialize(attrs = {}) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/esendex/hash_serialisation.rb', line 5 def initialize(attrs={}) attrs.each_pair do |k, v| raise ArgumentError.new("#{k} not an attribute of #{self.class.name}") unless respond_to?("#{k}=") send("#{k}=", v) end end |
#to_hash ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/esendex/hash_serialisation.rb', line 12 def to_hash attrs = {} public_methods .select { |m| m =~ /\w\=$/ } .select { |m| respond_to?(m.to_s.chop) } .collect { |m| m.to_s.chop.to_sym } .each do |method| attrs[method] = send(method) end attrs end |