Class: Pubid::Ieee::Identifiers::Nesc::Base

Inherits:
Pubid::Ieee::Identifier show all
Defined in:
lib/pubid/ieee/identifiers/nesc/base.rb

Overview

Base class for National Electrical Safety Code (NESC) identifiers

NESC is published by IEEE Standards Association and covers electrical safety standards for utilities and communication systems.

Reparented onto Pubid::Ieee::Identifier (it used to descend from bare Lutaml::Model::Serializable) so NESC shares #root, a polymorphic _type and from_hash routing with every other IEEE type — see Pubid::Ieee::Aiee::Identifier for the same migration. Three attributes were reconciled against the base to avoid type collisions:

`code`  -> travels as the runtime `code_obj` (base #code returns
         it); the concrete leaves serialize the flat split
         columns via the CodeNumber mixin.
`year`  -> the base's plain `:string` year (was a
         Pubid::Components::Date), matching IEEE's scalar-date
         convention. `nesc.year` is now "2017", not a component.
`draft` -> dropped; the base declares a `:string` `draft` (the draft
         *designator*), so a boolean here would corrupt it. Test
         draft-ness with `#draft?` / the Nesc::Draft class.

This class is abstract and enforces it in #initialize: the builder always instantiates a concrete leaf (Nesc::Edition for the plain year-first form), because only leaves may redefine number as a :string (see the CodeNumber mixin) and only leaves declare the NESC-specific polymorphic_name that from_hash routes on.

Examples:

Standard format

nesc = Pubid::Ieee.parse("C2-1997 National Electric Safety Code")
nesc.code.number # => "2"   (prefix "C")
nesc.year        # => "1997"

Handbook format

nesc = Pubid::Ieee.parse("2017 NESC Handbook, Premier Edition")
nesc.year        # => "2017"
nesc.variant     # => "Handbook"
nesc.edition     # => "Premier Edition"

Direct Known Subclasses

Draft, Edition, Handbook, Redline, Standard

Instance Attribute Summary

Attributes inherited from Pubid::Ieee::Identifier

#code_obj, #draft_obj

Instance Method Summary collapse

Methods inherited from Pubid::Ieee::Identifier

additional_identifier_classes, #code, #draft, #draft_month, #exclude, from_hash, #mr_number_with_part, #mr_publisher, #mr_type, #mr_year, parse, parse_single, #publisher, #to_hash

Methods inherited from Pubid::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?, #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

#initialize(args = {}, **kwargs) ⇒ Base

Guards the abstract contract — see the class docs. Ruby has no abstract, and an instantiated Base would carry the derived _type "pubid:ieee:base" (which from_hash cannot resolve back to NESC) and a nil number (the empty relaton index key).



59
60
61
62
63
64
65
66
67
# File 'lib/pubid/ieee/identifiers/nesc/base.rb', line 59

def initialize(args = {}, **kwargs)
  if instance_of?(Base)
    raise NotImplementedError,
          "#{self.class} is abstract; instantiate a concrete NESC " \
          "type (Standard, Edition, Handbook, Redline, Draft)"
  end

  super
end

Instance Method Details

#draft?Boolean

Whether this is a draft of the code. NESC has no draft attribute of its own (the base's draft is the draft designator string), so draft-ness lives in the class.

Returns:

  • (Boolean)


81
82
83
# File 'lib/pubid/ieee/identifiers/nesc/base.rb', line 81

def draft?
  is_a?(Nesc::Draft)
end

#name_portionString

The document-name portion, including the registered marks and the optional "(NESC(R))" abbreviation suffix.

Returns:

  • (String)

    e.g. "National Electrical Safety Code(R) (NESC(R))"



113
114
115
116
117
118
119
120
121
122
# File 'lib/pubid/ieee/identifiers/nesc/base.rb', line 113

def name_portion
  name = "National Electrical Safety Code"
  name += "(R)" if registered
  if abbr_suffix
    suffix = "NESC"
    suffix += "(R)" if abbr_suffix_registered
    name += " (#{suffix})"
  end
  name
end

#publisher_portionString

Publisher portion for NESC identifiers

Returns:

  • (String)

    Always returns "NESC"



72
73
74
# File 'lib/pubid/ieee/identifiers/nesc/base.rb', line 72

def publisher_portion
  "NESC"
end

#to_s(trademark: false) ⇒ String

Rendering for year-first NESC identifiers (the C2-code standard form overrides this in Nesc::Standard). IEEE catalogues the year-first editions with the "IEEE Std" prefix, so it is prepended here.

Parameters:

  • trademark (Boolean) (defaults to: false)

    append the IEEE trademark symbol (™/®)

Returns:

  • (String)

    String representation



91
92
93
94
95
# File 'lib/pubid/ieee/identifiers/nesc/base.rb', line 91

def to_s(trademark: false)
  result = ["IEEE Std", year, name_portion].compact.join(" ")
  result += trademark_symbol if trademark
  result
end

#trademark_symbolString

Trademark symbol for this document's own code. A NESC string starts with the publication year, so the string-scanning Pubid::Ieee.trademark_symbol would pick the wrong field — an edition year of 2030 would silently render ®.

Returns:

  • (String)

    "®" or "™"



103
104
105
106
107
# File 'lib/pubid/ieee/identifiers/nesc/base.rb', line 103

def trademark_symbol
  Pubid::Ieee.trademark_symbol_for(code_obj&.number,
                                   code_obj&.prefix,
                                   publishers: [publisher])
end