Class: OpenMarket::MO

Inherits:
Object
  • Object
show all
Defined in:
lib/open_market/mo.rb

Constant Summary collapse

ATTRIBUTES =
[:account_id, :carrier_id, :data, :data_coding, :destination_address, :destination_ton, :source_address, :source_ton, :ticket_id, :udhi]

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ MO

Returns a new instance of MO.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/open_market/mo.rb', line 7

def initialize(data)
  (class << self; self; end).class_eval do
    # Defining a member variable for xml would pollute #inspect
    # This solution is inspired by https://github.com/jordansissel/software-patterns/tree/master/dont-log-secrets/ruby
    define_method(:xml) { REXML::Document.new(data).root }
    private :xml
  end
  if ticket = xml.elements["ticket"]
    @ticket_id = ticket.attributes["id"]
  end
  if  = xml.elements["account"]
    @account_id = .attributes["id"]
  end
  if source = xml.elements["source"]
    @source_address = source.attributes["address"]
    @carrier_id = source.attributes["carrier"]
    @source_ton = source.attributes["ton"]
  end
  if destination = xml.elements["destination"]
    @destination_address = destination.attributes["address"]
    @destination_ton = destination.attributes["ton"]
  end
  if option = xml.elements["option"]
    @data_coding = option.attributes["datacoding"]
  end
  if message = xml.elements["message"]
    @udhi = message.attributes["udhi"] == true
    @data = [message.attributes["data"]].pack("H*").unpack("C*").pack("U*")
  end
end

Instance Method Details

#==(rhs) ⇒ Object



38
39
40
# File 'lib/open_market/mo.rb', line 38

def ==(rhs)
  rhs.is_a?(self.class) && ATTRIBUTES.all? { |a| send(a) == rhs.send(a) }
end