class SAML2::AttributeStatement
Attributes
attributes[R]
Public Class Methods
new(attributes = [])
click to toggle source
Calls superclass method
# File lib/saml2/attribute.rb, line 165 def initialize(attributes = []) super() @attributes = attributes end
Public Instance Methods
build(builder)
click to toggle source
# File lib/saml2/attribute.rb, line 213 def build(builder) builder["saml"].AttributeStatement("xmlns:xs" => Namespaces::XS, "xmlns:xsi" => Namespaces::XSI) do |statement| @attributes.each { |attr| attr.build(statement) } end end
from_xml(node)
click to toggle source
Calls superclass method
# File lib/saml2/attribute.rb, line 170 def from_xml(node) super @attributes = node.xpath("saml:Attribute", Namespaces::ALL).map do |attr| Attribute.from_xml(attr) end end
to_h(name = :both)
click to toggle source
Convert the {AttributeStatement} to a {Hash}
Repeated attributes become an array.
@param name optional [:name, :friendly_name, :both]
Which name field to use as keys to the hash. If :both is specified, attributes may be duplicated under both names.
# File lib/saml2/attribute.rb, line 185 def to_h(name = :both) return to_h(:friendly_name).merge(to_h(:name)) if name == :both result = {} attributes.each do |attribute| key = attribute.send(name) # fall back to name on missing friendly name; # no need for the opposite, because name is required key ||= attribute.name if name == :friendly_name prior_value = result[key] result[key] = if prior_value value = Array.wrap(prior_value) # repeated key; convert to array if attribute.value.is_a?(Array) # both values are arrays; concatenate them value.concat(attribute.value) else value << attribute.value end value else attribute.value end end result end