Class: Pubid::Ecma::Identifier

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

Overview

Base class for every ECMA identifier AND the flavor's parse entry point — mirrors Pubid::Jis::Identifier. Concrete identifiers under Pubid::Ecma::Identifiers descend from this class, so a parsed ECMA id is an instance of Pubid::Ecma::Identifier. ECMA has no supplement layer.

Constant Summary collapse

ECMA_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:ecma:standard" => "Pubid::Ecma::Identifiers::Standard",
  "pubid:ecma:technical-report" =>
    "Pubid::Ecma::Identifiers::TechnicalReport",
  "pubid:ecma:memento" => "Pubid::Ecma::Identifiers::Memento",
}.freeze
PUBLISHER =

Publisher is always "ECMA". A plain constant (not a publisher method) so it doesn't shadow the inherited lutaml publisher attribute, which would otherwise fail serialization type validation.

"ECMA"

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)

Whether the last to_s should include the "ECMA" publisher token.



44
45
46
# File 'lib/pubid/ecma/identifier.rb', line 44

def with_publisher
  @with_publisher
end

Class Method Details

.parse(identifier) ⇒ Identifier

Parse an ECMA identifier string into an identifier object.

Parameters:

  • identifier (String)

    The ECMA identifier string to parse

Returns:

  • (Identifier)

    The appropriate identifier object

Raises:

  • (ArgumentError)

    If the input exceeds MAX_INPUT_LENGTH

  • (RuntimeError)

    If parsing fails



64
65
66
67
68
69
70
71
72
73
# File 'lib/pubid/ecma/identifier.rb', line 64

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 ECMA identifier '#{identifier}': #{e.message}"
end

Instance Method Details

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

Basic string representation. Delegates to renderer. with_publisher: false drops the ECMA token (e.g. "-411", "TR/84").



48
49
50
51
# File 'lib/pubid/ecma/identifier.rb', line 48

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

#type_prefixObject

Type token that precedes the number ("TR"/"MEM"), or nil for standards. Overridden by each concrete identifier class.



55
56
57
# File 'lib/pubid/ecma/identifier.rb', line 55

def type_prefix
  nil
end