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)
Human render: abbreviation with flavor-specific separator. URN render: type code (e.g. “tr”, “ts”) per RFC 5141-bis.
Direct Known Subclasses
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #render(context: nil) ⇒ Object
- #to_s(context: nil, has_prefix: false) ⇒ Object
Instance Method Details
#eql?(other) ⇒ 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 |
#hash ⇒ Object
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 |