Class: Pubid::Xsf::Identifier

Inherits:
Identifier
  • Object
show all
Defined in:
lib/pubid/xsf/identifier.rb

Overview

Base class for every XSF identifier AND the flavor's parse/create entry point — mirrors Pubid::Jis::Identifier. The single concrete type (Pubid::Xsf::Identifiers::Xep) descends from this class, so a parsed XSF id is an instance of Pubid::Xsf::Identifier.

Direct Known Subclasses

Pubid::Xsf::Identifiers::Xep

Constant Summary collapse

XSF_TYPE_MAP =

Polymorphic type map for lutaml::Model key_value (de)serialization: maps each subclass's polymorphic_name to its class name so a stored hash rebuilds the correct identifier type via from_hash.

{
  "pubid:xsf:xep" => "Pubid::Xsf::Identifiers::Xep",
}.freeze
PUBLISHER =

Publisher name. A plain constant (not a publisher method) so it does not shadow the inherited lutaml publisher attribute, which would otherwise fail serialization type validation. XSF never prints its publisher name in an identifier — the leading token is "XEP".

"XSF"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Identifier

apply_mappings, #base, #base_document, concrete_class_for, #dated_version_of?, #draft_of?, #drop_supplements, #edition_of?, #eql?, #exclude, from_hash, #has_supplement?, #hash, #includes?, #initialize, #matches?, #mr_all_parts, #mr_edition, #mr_languages, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_subpart, #mr_supplement_suffix, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, polymorphic_type_map, #related_to?, #render, #resolve_urn_generator, #root, #sibling_of?, #supplement_of?, #to_hash, #to_mr_string, #to_slug, #to_supplement_s, #to_urn, #urn_supplement_type, #urn_type_code, #year

Constructor Details

This class inherits a constructor from Pubid::Identifier

Instance Attribute Details

#with_publisherObject (readonly)

Returns the value of attribute with_publisher.



33
34
35
# File 'lib/pubid/xsf/identifier.rb', line 33

def with_publisher
  @with_publisher
end

Class Method Details

.parse(identifier) ⇒ Identifier

Parse an XSF identifier string into an identifier object

Parameters:

  • identifier (String)

    The XSF identifier string to parse

Returns:

  • (Identifier)

    The appropriate identifier object

Raises:

  • (ArgumentError)

    If the input exceeds the maximum length

  • (RuntimeError)

    If parsing fails



50
51
52
53
54
55
56
57
58
59
# File 'lib/pubid/xsf/identifier.rb', line 50

def self.parse(identifier)
  if identifier.length > Pubid::MAX_INPUT_LENGTH
    raise ArgumentError, Pubid::INPUT_TOO_LONG_MESSAGE
  end

  parsed = Parser.parse(identifier)
  Builder.build(parsed)
rescue Parslet::ParseFailed => e
  raise "Failed to parse XSF identifier '#{identifier}': #{e.message}"
end

Instance Method Details

#to_s(with_publisher: true, **opts) ⇒ Object

Basic string representation. Delegates to renderer; with_publisher: false yields the bare number.



37
38
39
40
# File 'lib/pubid/xsf/identifier.rb', line 37

def to_s(with_publisher: true, **opts)
  @with_publisher = with_publisher
  render(format: :human, **opts)
end