Module: Metanorma::Iso::PublisherIdentity

Defined in:
lib/metanorma/iso/publisher_identity.rb

Overview

Canonical "is this node published by ISO / IEC?" check, shared across the metanorma-converter layer (bare xpath) and the isodoc layer (namespaced xpath). Pass the converter's #ns as the ns: resolver in the isodoc layer; the default identity resolver is correct for the un-namespaced Semantic XML of the cleanup layer. Deliberately NOT pub_class, which is sort-oriented and overridden per flavour.

Constant Summary collapse

PUBLISHER =
"./contributor[role/@type = 'publisher']/organization".freeze
ISO_NAME =
"International Organization for Standardization".freeze
IEC_NAME =
"International Electrotechnical Commission".freeze
IDENTITY_NS =
->(xpath) { xpath }

Class Method Summary collapse

Class Method Details

.iec_publisher?(node, ns: IDENTITY_NS) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/metanorma/iso/publisher_identity.rb', line 21

def iec_publisher?(node, ns: IDENTITY_NS)
  publisher_match?(node, ns, "IEC", IEC_NAME)
end

.iso_iec_publisher?(node, ns: IDENTITY_NS) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/metanorma/iso/publisher_identity.rb', line 25

def iso_iec_publisher?(node, ns: IDENTITY_NS)
  iso_publisher?(node, ns: ns) || iec_publisher?(node, ns: ns)
end

.iso_publisher?(node, ns: IDENTITY_NS) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/metanorma/iso/publisher_identity.rb', line 17

def iso_publisher?(node, ns: IDENTITY_NS)
  publisher_match?(node, ns, "ISO", ISO_NAME)
end

.publisher_match?(node, ns, abbr, name) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
# File 'lib/metanorma/iso/publisher_identity.rb', line 29

def publisher_match?(node, ns, abbr, name)
  node or return false
  !!(node.at(ns.call("#{PUBLISHER}[abbreviation = '#{abbr}']")) ||
     node.at(ns.call("#{PUBLISHER}[name = '#{name}']")))
end