Sha256: 8fc0a81c1df28c29fbb992fe3b3300c8050dc5c9473ba4cdc6009bd74cacedaf
Contents?: true
Size: 1.93 KB
Versions: 11
Compression:
Stored size: 1.93 KB
Contents
require 'xml/mapping_extensions' module Datacite module Mapping # Controlled vocabulary of title types (for titles other than the main/default title). class TitleType < TypesafeEnum::Base # @!parse ALTERNATIVE_TITLE = AlternativeTitle new :ALTERNATIVE_TITLE, 'AlternativeTitle' # @!parse SUBTITLE = Subtitle new :SUBTITLE, 'Subtitle' # @!parse TRANSLATED_TITLE = TranslatedTitle new :TRANSLATED_TITLE, 'TranslatedTitle' end # A name or title by which a {Resource} is known. class Title include XML::Mapping # Initializes a new {Title}. # @param language [String] an IETF BCP 47, ISO 639-1 language code identifying the language. # It's unclear from the spec whether language is required; to play it safe, if it's missing, we default to 'en'. # @param value [String] the title itself. # @param type [TitleType, nil] the title type. Optional. def initialize(language: 'en', value:, type: nil) self.language = language self.type = type self.value = value end def language @language || 'en' end def language=(value) @language = value.strip if value end def value=(v) fail ArgumentError, 'Value cannot be empty or nil' unless v && !v.empty? @value = v.strip end # @!attribute [rw] language # @return [String] an IETF BCP 47, ISO 639-1 language code identifying the language. # It's unclear from the spec whether language is required; to play it safe, if it's missing, we default to 'en'. text_node :language, '@xml:lang', default_value: nil # @!attribute [rw] type # @return [TitleType, nil] the title type. Optional. typesafe_enum_node :type, '@titleType', class: TitleType, default_value: nil # @!attribute [rw] value # @return [String] the title itself. text_node :value, 'text()' end end end
Version data entries
11 entries across 11 versions & 1 rubygems