Sha256: 3dca9142636d0de13c966a6037e58eeb4c37485f6840bdf02af5d586809ef47f

Contents?: true

Size: 1.04 KB

Versions: 10

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

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

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

    # @return [String]
    attr_accessor :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

    # @return [TrueClass, FalseClass]
    def empty?
      content.empty?
    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

10 entries across 10 versions & 1 rubygems

Version Path
relaton-bib-0.3.3 lib/relaton_bib/localized_string.rb
relaton-bib-0.3.2 lib/relaton_bib/localized_string.rb
relaton-bib-0.3.1 lib/relaton_bib/localized_string.rb
relaton-bib-0.3.0 lib/relaton_bib/localized_string.rb
relaton-bib-0.2.5 lib/relaton_bib/localized_string.rb
relaton-bib-0.2.4 lib/relaton_bib/localized_string.rb
relaton-bib-0.2.3 lib/relaton_bib/localized_string.rb
relaton-bib-0.2.2 lib/relaton_bib/localized_string.rb
relaton-bib-0.2.1 lib/relaton_bib/localized_string.rb
relaton-bib-0.2.0 lib/relaton_bib/localized_string.rb