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
# File 'lib/saml2/localized_name.rb', line 10

def initialize(element, name = nil)
  @element = element
  unless name.nil?
    if name.is_a?(Hash)
      replace(name)
    else
      self[nil] = name
    end
  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)

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

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

#build(builder) ⇒ Object


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

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

#from_xml(nodes) ⇒ Object


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

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


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

def to_s
  self[nil].to_s
end