Class: IsoBibItem::LocalizedString

Inherits:
Object
  • Object
show all
Defined in:
lib/iso_bib_item/localized_string.rb

Overview

Localized string.

Direct Known Subclasses

FormattedString

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, language = nil, script = nil) ⇒ LocalizedString

Returns a new instance of LocalizedString.

Parameters:

  • content (String)
  • language (String) (defaults to: nil)

    language code Iso639

  • script (String) (defaults to: nil)

    script code Iso15924



18
19
20
21
22
23
24
# File 'lib/iso_bib_item/localized_string.rb', line 18

def initialize(content, language = nil, script = nil)
  @language = []
  @language << language if language
  @script = []
  @script << script if script
  @content = content
end

Instance Attribute Details

#contentString (readonly)

Returns:

  • (String)


13
14
15
# File 'lib/iso_bib_item/localized_string.rb', line 13

def content
  @content
end

#languageArray<String>

Returns language Iso639 code.

Returns:

  • (Array<String>)

    language Iso639 code



7
8
9
# File 'lib/iso_bib_item/localized_string.rb', line 7

def language
  @language
end

#scriptArray<String>

Returns script Iso15924 code.

Returns:

  • (Array<String>)

    script Iso15924 code



10
11
12
# File 'lib/iso_bib_item/localized_string.rb', line 10

def script
  @script
end

Instance Method Details

#to_sString

Returns:

  • (String)


27
28
29
# File 'lib/iso_bib_item/localized_string.rb', line 27

def to_s
  content
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


32
33
34
35
36
37
# File 'lib/iso_bib_item/localized_string.rb', line 32

def to_xml(builder)
  return unless content
  builder.parent['language'] = language.join(',') if language.any?
  builder.parent['script']   = script.join(',') if script.any?
  builder.text content
end