Class: Pubid::Components::Type
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Pubid::Components::Type
- Defined in:
- lib/pubid/components/type.rb
Overview
Resource type component (a set of defined resource types)
Direct Known Subclasses
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
Checks equality with another type component.
-
#hash ⇒ Integer
Returns hash code for type component.
- #render(context: nil) ⇒ Object
-
#to_s(context: nil, has_prefix: false) ⇒ String
Render type with optional context for flavor-specific separators and default handling.
Instance Method Details
#eql?(other) ⇒ Boolean
Checks equality with another type component
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 |
#hash ⇒ Integer
Note:
Memoized for performance
Returns hash code for type component
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
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 |