Module: Xommelier::Xml::Element::Serialization::ClassMethods

Defined in:
lib/xommelier/xml/element/serialization.rb

Instance Method Summary collapse

Instance Method Details

#element_xpath(xml_doc = nil, name = nil) ⇒ Object



40
41
42
# File 'lib/xommelier/xml/element/serialization.rb', line 40

def element_xpath(xml_doc = nil, name = nil)
  ns_element(xmlns_xpath(xml_doc), name || element_name)
end

#from_xml(xml, options = {}) ⇒ Object Also known as: parse, from_xommelier



27
28
29
30
31
# File 'lib/xommelier/xml/element/serialization.rb', line 27

def from_xml(xml, options = {})
  new({}, options).tap do |doc|
    doc.from_xml(xml, options)
  end
end

#ns_element(ns, element) ⇒ Object



36
37
38
# File 'lib/xommelier/xml/element/serialization.rb', line 36

def ns_element(ns, element)
  [ns, element].compact.join(':')
end

#xmlns_xpath(xml_doc = nil) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/xommelier/xml/element/serialization.rb', line 44

def xmlns_xpath(xml_doc = nil)
  if xml_doc
    prefix = xml_doc.namespaces.key(xmlns.try(:uri))
    (prefix =~ /:/) ? prefix[6..-1] : prefix
  else
    xmlns.as
  end
end