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)

Direct Known Subclasses

Bsi::Components::Type

Instance Method Summary collapse

Instance Method Details

#eql?(other) ⇒ Boolean

Checks equality with another type component

Parameters:

  • other (Object)

    object to compare with

Returns:

  • (Boolean)

    true if equal



51
52
53
54
55
# File 'lib/pubid/components/type.rb', line 51

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

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

#hashInteger

Note:

Memoized for performance

Returns hash code for type component

Returns:

  • (Integer)

    hash code



44
45
46
# File 'lib/pubid/components/type.rb', line 44

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

#render(context: nil) ⇒ Object



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

def render(context: nil)
  name.to_s
end

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

Render type with optional context for flavor-specific separators and default handling

Parameters:

  • context (RenderingContext) (defaults to: nil)

    rendering context for flavor rules

  • has_prefix (Boolean) (defaults to: false)

    whether there’s a prefix (stage or copublisher)

Returns:

  • (String)

    rendered type string



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pubid/components/type.rb', line 20

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

  # Check if this type should be rendered (not the default)
  if context && !context.should_render_type?(abbr)
    return ""
  end

  if context
    sep = context.type_separator_for(has_prefix)
    sep == "" ? abbr : "#{sep}#{abbr}"
  else
    # Default behavior: space after prefix, slash otherwise
    has_prefix ? " #{abbr}" : "/#{abbr}"
  end
end