Class: Pubid::Bsi::Identifier
- Inherits:
-
Identifier
- Object
- Lutaml::Model::Serializable
- Identifier
- Pubid::Bsi::Identifier
- Defined in:
- lib/pubid/bsi/model.rb,
lib/pubid/bsi/single_identifier.rb
Overview
BSI base class. Canonical name Pubid::Bsi::Identifier; SingleIdentifier is a
back-compat alias (BSI's common ancestor — there is no Identifiers::Base).
Every concrete BSI identifier descends from it, so they are all
is_a?(Pubid::Bsi::Identifier) natively and get the shared polymorphic
from_hash (no facade needed).
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Identifier
#base_identifier, #eql?, #exclude, from_hash, #hash, #initialize, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, polymorphic_type_map, #render, #resolve_urn_generator, #root, #to_hash, #to_mr_string, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year
Constructor Details
This class inherits a constructor from Pubid::Identifier
Class Method Details
.parse(string) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pubid/bsi/single_identifier.rb', line 11 def self.parse(string) if string.length > Pubid::MAX_INPUT_LENGTH raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE end # Delegate to IEC for bare IEC identifiers. This handles IEC-specific # features like VAP suffixes (CSV, RLV, etc.) and consolidated # supplements (+AMD1:2001). if string.match?(/\bIEC\b/) && (string.match?(/\s+(CSV|CMV|RLV|SER|EXV|PAC|PRV)\b/) || string.match?(/\+AMD\d+:/) || string.match?(/\+COR\d+:/)) return Pubid::Iec.parse(string) end parser = Parser.new parsed = parser.parse(string) Builder.build(parsed) rescue Parslet::ParseFailed => e raise StandardError, "Failed to parse '#{string}': #{e.}" end |
Instance Method Details
#<=>(other) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pubid/bsi/single_identifier.rb', line 56 def <=>(other) return nil unless other.is_a?(Pubid::Bsi::Identifier) # Compare by number first num_cmp = number.to_s <=> other.number.to_s return num_cmp unless num_cmp.zero? # Then by part part_cmp = (part || Components::Code.new(value: "0")).to_s <=> (other.part || Components::Code.new(value: "0")).to_s return part_cmp unless part_cmp.zero? # Then by date if date && other.date date.to_s <=> other.date.to_s elsif date 1 elsif other.date -1 else 0 end end |
#to_s ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/pubid/bsi/model.rb', line 76 def to_s # Handle national annex if national_annex return render_national_annex end # Handle expert commentary if expert_commentary base_id = self.class.new( type: type, number: number, part: part, year: year, month: month, supplements: supplements, adopted: adopted, ) return "#{base_id} ExComm" end # Handle collection (combined documents) if second_number return render_collection end # Regular identifier render_identifier end |