Class: SAML2::LocalizedName

Inherits:
Hash
  • Object
show all
Defined in:
lib/saml2/localized_name.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, name = nil) ⇒ LocalizedName

Returns a new instance of LocalizedName.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/saml2/localized_name.rb', line 10

def initialize(element, name = nil)
  super()
  @element = element
  return if name.nil?

  if name.is_a?(Hash)
    replace(name)
  else
    self[nil] = name
  end
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



8
9
10
# File 'lib/saml2/localized_name.rb', line 8

def element
  @element
end

Instance Method Details

#[](lang) ⇒ String

Parameters:

  • lang (String, Symbol, :all, nil)

    The language to retrieve the localized string for. :all will return the hash itself, and nil will return the first localized string regardless of language.

Returns:

  • (String)


27
28
29
30
31
32
33
34
35
36
# File 'lib/saml2/localized_name.rb', line 27

def [](lang)
  case lang
  when :all
    self
  when nil
    !empty? && first.last
  else
    super(lang.to_sym)
  end
end

#build(builder) ⇒ Object



51
52
53
54
55
# File 'lib/saml2/localized_name.rb', line 51

def build(builder)
  each do |lang, value|
    builder["md"].__send__(element, value, "xml:lang" => lang)
  end
end

#from_xml(nodes) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/saml2/localized_name.rb', line 43

def from_xml(nodes)
  clear
  nodes.each do |node|
    self[node["xml:lang"].to_sym] = node.content && node.content.strip
  end
  self
end

#to_sString

Returns The first localized string regardless of language.

Returns:

  • (String)

    The first localized string regardless of language



39
40
41
# File 'lib/saml2/localized_name.rb', line 39

def to_s
  self[nil].to_s
end