Class: OpenMarket::MO
- Inherits:
-
Object
- Object
- OpenMarket::MO
- 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
- #==(rhs) ⇒ Object
-
#initialize(data) ⇒ MO
constructor
A new instance of MO.
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 account = xml.elements["account"] @account_id = account.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 = xml.elements["message"] @udhi = .attributes["udhi"] == true @data = [.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 |