class SAML2::AttributeStatement
Attributes
Public Class Methods
Source
# File lib/saml2/attribute.rb, line 166 def initialize(attributes = []) super() @attributes = attributes end
Calls superclass method
Public Instance Methods
Source
# File lib/saml2/attribute.rb, line 214 def build(builder) builder["saml"].AttributeStatement("xmlns:xs" => Namespaces::XS, "xmlns:xsi" => Namespaces::XSI) do |statement| @attributes.each { |attr| attr.build(statement) } end end
Source
# File lib/saml2/attribute.rb, line 171 def from_xml(node) super @attributes = node.xpath("saml:Attribute", Namespaces::ALL).map do |attr| Attribute.from_xml(attr) end end
Calls superclass method
Source
# File lib/saml2/attribute.rb, line 186 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
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.