Class: Pubid::Itu::Components::Code
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Pubid::Itu::Components::Code
- Defined in:
- lib/pubid/itu/components/code.rb
Overview
ITU Code component Format: [Imp]NUMBER[.SUBSERIES][-PART] Examples: 1234, 1234.5, 1234-1, 1234.5-2, 50bis, 8bis, Imp712, ImpOSI
The optional "Imp" marker identifies an Implementers' Guide for the series (e.g. G.Imp712, X.ImpOSI); the NUMBER that follows may be digits or a short letter string.
SUFFIX is the edition marker "bis" / "ter" / "quater" attached directly to the number (e.g. X.50bis, V.8bis).
Stays independent of Pubid::Components::Code because ITU uses
subseries (dot-separated, flavor-specific) and parts
(dash-separated).
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#compact_s ⇒ Object
Space-free rendering for URN and MR use: the print form may separate the edition word or the qualifier letter with a space ("E.250 bis", "D.200 R"), which is not admissible inside a URN segment.
- #render(context: nil) ⇒ Object
-
#to_s ⇒ Object
Segment order mirrors the grammar exactly — a GLUED suffix is captured inside
standard_code(the edition word before the subseries, the qualifier after the parts), while a SPACED one is captured afterwards bycode_suffixes.
Instance Method Details
#==(other) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pubid/itu/components/code.rb', line 71 def ==(other) return false unless other.is_a?(Code) imp_marker == other.imp_marker && number == other.number && series_suffix == other.series_suffix && subseries == other.subseries && parts == other.parts && qualifier == other.qualifier end |
#compact_s ⇒ Object
Space-free rendering for URN and MR use: the print form may separate the edition word or the qualifier letter with a space ("E.250 bis", "D.200 R"), which is not admissible inside a URN segment. Removing the space keeps "D.200" and "D.200 R" on distinct URNs, which dropping the suffix would not.
63 64 65 |
# File 'lib/pubid/itu/components/code.rb', line 63 def compact_s to_s.delete(" ") end |
#render(context: nil) ⇒ Object
67 68 69 |
# File 'lib/pubid/itu/components/code.rb', line 67 def render(context: nil) to_s end |
#to_s ⇒ Object
Segment order mirrors the grammar exactly — a GLUED suffix is
captured inside standard_code (the edition word before the
subseries, the qualifier after the parts), while a SPACED one is
captured afterwards by code_suffixes. Rendering the edition word
unconditionally first would print "Q.11a bis" back as "Q.11 bisa".
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/pubid/itu/components/code.rb', line 47 def to_s result = "#{imp_marker}#{number}" result += series_suffix.to_s if series_suffix && !series_suffix_spaced result += ".#{subseries}" if subseries result += parts.map { |p| "-#{p}" }.join if parts&.any? result += qualifier.to_s if qualifier && qualifier_glued result += " #{series_suffix}" if series_suffix && series_suffix_spaced result += " #{qualifier}" if qualifier && !qualifier_glued result end |