Class: Pubid::Bsi::SingleIdentifier
- Inherits:
-
Identifier
- Object
- Lutaml::Model::Serializable
- Identifier
- Pubid::Bsi::SingleIdentifier
- Defined in:
- lib/pubid/bsi/single_identifier.rb
Direct Known Subclasses
Identifiers::AerospaceStandard, Identifiers::BritishStandard, Identifiers::CommitteeDocument, Identifiers::DetailedSpecification, Identifiers::Disc, Identifiers::DraftDocument, Identifiers::ElectronicBook, Identifiers::ExplanatorySupplement, Identifiers::Flex, Identifiers::Index, Identifiers::Method, Identifiers::NationalAnnex, Identifiers::PubliclyAvailableSpecification, Identifiers::PublishedDocument, Identifiers::Section, Identifiers::StandaloneAmendment, Identifiers::SupplementaryIndex, Identifiers::TechnicalSpecification, Identifiers::TestMethod
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#publisher ⇒ String
Generate URN for this identifier.
- #to_s(lang: :en, lang_single: false) ⇒ Object
Methods inherited from Identifier
#base_identifier, #eql?, #exclude, #hash, #initialize, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, #render, #resolve_urn_generator, #root, #to_mr_string, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code
Constructor Details
This class inherits a constructor from Pubid::Identifier
Instance Method Details
#<=>(other) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/pubid/bsi/single_identifier.rb', line 105 def <=>(other) return nil unless other.is_a?(SingleIdentifier) # 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 |
#publisher ⇒ String
Generate URN for this identifier
10 11 12 |
# File 'lib/pubid/bsi/single_identifier.rb', line 10 attribute :publisher, Bsi::Components::Publisher, default: -> { Bsi::Components::Publisher.new(body: "BS") } |
#to_s(lang: :en, lang_single: false) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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/single_identifier.rb', line 32 def to_s(lang: :en, lang_single: false) # Build string representation parts = [] # For supplement/addendum base identifiers, flex_prefix replaces publisher+prefix parts << publisher.to_s if publisher if flex_prefix # Flex prefix is the full prefix including BS (e.g., "BS CECC" becomes "BS" + space + "CECC") parts << flex_prefix elsif prefix # Standard publisher # Prefix if present (specialized prefix like A, AU, C, etc.) parts << prefix.to_s end # Number with iteration, part, and subpart if number number_str = number.is_a?(Components::Code) ? number.value.to_s : number.to_s # Collection (second number with slash) if second_number second_val = second_number.is_a?(Components::Code) ? second_number.value : second_number number_str += "/#{second_val}" end # Part and subpart - check if space-separated space_separated = space_separated_part if part part_val = part.is_a?(Components::Code) ? part.value : part # Trim part value to remove leading/trailing spaces from parser part_str = part_val.to_s.strip # Use space for space-separated parts, dash otherwise separator = space_separated ? " " : "-" number_str += "#{separator}#{part_str}" end if subpart subpart_val = subpart.is_a?(Components::Code) ? subpart.value : subpart subpart_str = subpart_val.to_s.strip number_str += "-#{subpart_str}" end # Iteration (bracket notation like 1000[9]) if iteration && !iteration.empty? number_str += "[#{iteration}]" end parts << number_str end result = parts.join(" ") # Date if date year_val = date.is_a?(Components::Date) ? date.year : date.to_i result += ":#{year_val}" # Month if present result += "-#{format('%02d', month)}" if month end # Edition result += " v#{edition}" if edition # Translation if translation_lang result += " (#{translation_lang})" elsif translation_upper result += " (#{translation_upper})" end result end |