Class: Pubid::Components::Type

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

Overview

Resource type component (a set of defined resource types)

Human render: abbreviation with flavor-specific separator. URN render: type code (e.g. “tr”, “ts”) per RFC 5141-bis.

Direct Known Subclasses

Bsi::Components::Type

Instance Method Summary collapse

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/pubid/components/type.rb', line 41

def eql?(other)
  return false unless other.is_a?(self.class)

  type_code == other.type_code && abbr == other.abbr
end

#hashObject



37
38
39
# File 'lib/pubid/components/type.rb', line 37

def hash
  @hash ||= [type_code, abbr].compact.map(&:hash).hash
end

#render(context: nil) ⇒ Object



31
32
33
34
35
# File 'lib/pubid/components/type.rb', line 31

def render(context: nil)
  return type_code.to_s if context&.urn? && type_code

  name.to_s
end

#to_s(context: nil, has_prefix: false) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pubid/components/type.rb', line 16

def to_s(context: nil, has_prefix: false)
  return "" unless abbr

  if context && !context.should_render_type?(abbr)
    return ""
  end

  if context
    sep = context.type_separator_for(has_prefix)
    sep == "" ? abbr : "#{sep}#{abbr}"
  else
    has_prefix ? " #{abbr}" : "/#{abbr}"
  end
end