Sha256: 8f41614b28846c4f64f54b7f779d49a2ae3c3156486e218bb852542164899e62

Contents?: true

Size: 980 Bytes

Versions: 13

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true

module IsoBibItem
  # Localized string.
  class LocalizedString
    # @return [Array<String>] language Iso639 code
    attr_accessor :language

    # @return [Array<String>] script Iso15924 code
    attr_accessor :script

    # @return [String]
    attr_reader :content

    # @param content [String]
    # @param language [String] language code Iso639
    # @param script [String] script code Iso15924
    def initialize(content, language = nil, script = nil)
      @language = []
      @language << language if language
      @script = []
      @script << script if script
      @content = content
    end

    # @return [String]
    def to_s
      content
    end

    # @param builder [Nokogiri::XML::Builder]
    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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
iso-bib-item-0.4.5 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.4.4 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.4.3 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.4.2 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.4.1 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.4.0 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.3.1 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.3.0 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.2.5 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.2.4 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.2.3 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.2.2 lib/iso_bib_item/localized_string.rb
iso-bib-item-0.2.1 lib/iso_bib_item/localized_string.rb