Guest User

Untitled

a guest
Jul 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. require 'nokogiri'
  2.  
  3. class PostPayload
  4. attr_accessor :mac_address, :ip_address, :xml, :xml_document
  5.  
  6. def initialize(params)
  7. @mac_address = params[:mac_address]
  8. @ip_address = params[:ip_address]
  9. @xml = params[:xml]
  10.  
  11. @xml_document = load_xml
  12.  
  13. end
  14.  
  15. # Extract the field from the xml payload
  16. def method_missing(method, *args, &block)
  17. if method.to_s =~ /^find_(.*)/
  18. puts "Looking for node named #{$1}"
  19. return content = @xml_document.css("#{$1}").first.content.to_s
  20. end
  21. super
  22. end
  23.  
  24. private
  25. def load_xml
  26. xml_doc = Nokogiri::XML(@xml)
  27. end
  28.  
  29. end
Add Comment
Please, Sign In to add comment