Class: Pubid::Nist::Components::Translation

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/pubid/nist/components/translation.rb

Overview

Translation component for NIST publications Uses 3-letter ISO 639-2 language codes

Examples:

Translation.new(code: "spa").to_s(:short) # => " spa"
Translation.new(code: "por").to_s(:mr)    # => ".por"
Translation.new(code: "ind").to_s(:short) # => " ind"

Instance Method Summary collapse

Instance Method Details

#languageString?

Backward compatibility: language method returns code

Returns:

  • (String, nil)

    language code



20
21
22
# File 'lib/pubid/nist/components/translation.rb', line 20

def language
  code
end

#to_s(format = :short) ⇒ String

Render translation in specified format

Parameters:

  • format (:short, :mr, :long) (defaults to: :short)

    The output format

Returns:

  • (String)

    The formatted translation representation



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pubid/nist/components/translation.rb', line 27

def to_s(format = :short)
  return "" if code.nil?

  case format
  when :short, :long
    " #{code}"
  when :mr
    ".#{code}"
  else
    " #{code}"
  end
end