Module: Saml::Kit::XmlParseable

Included in:
AttributeStatement, Conditions, Document, Metadata, Organization
Defined in:
lib/saml/kit/concerns/xml_parseable.rb

Constant Summary collapse

NAMESPACES =
{
  NameFormat: ::Saml::Kit::Namespaces::ATTR_SPLAT,
  ds: ::Xml::Kit::Namespaces::XMLDSIG,
  md: ::Saml::Kit::Namespaces::METADATA,
  saml: ::Saml::Kit::Namespaces::ASSERTION,
  samlp: ::Saml::Kit::Namespaces::PROTOCOL,
  xmlenc: ::Xml::Kit::Namespaces::XMLENC,
}.freeze

Instance Method Summary collapse

Instance Method Details

#present?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/saml/kit/concerns/xml_parseable.rb', line 36

def present?
  to_s.present?
end

#to_hObject

Returns the SAML document returned as a Hash.



18
19
20
# File 'lib/saml/kit/concerns/xml_parseable.rb', line 18

def to_h
  @to_h ||= Hash.from_xml(to_s) || {}
end

#to_sObject

Returns the XML document as a [String].



58
59
60
# File 'lib/saml/kit/concerns/xml_parseable.rb', line 58

def to_s
  content
end

#to_xhtmlObject

Returns the SAML document as an XHTML string. This is useful for rendering in a web page.



32
33
34
# File 'lib/saml/kit/concerns/xml_parseable.rb', line 32

def to_xhtml
  Nokogiri::XML(to_xml, &:noblanks).to_xhtml
end

#to_xml(pretty: nil) ⇒ Object

Returns the XML document as a String.

of the XML.

Parameters:

  • pretty (Boolean) (defaults to: nil)

    true to return a human friendly version



26
27
28
# File 'lib/saml/kit/concerns/xml_parseable.rb', line 26

def to_xml(pretty: nil)
  pretty ? to_nokogiri.to_xml(indent: 2) : to_s
end