Module: Pubid::Gb
- Extended by:
- PrefixesSupport
- Defined in:
- lib/pubid/gb.rb,
lib/pubid/gb/parser.rb,
lib/pubid/gb/builder.rb,
lib/pubid/gb/renderer.rb,
lib/pubid/gb/identifier.rb,
lib/pubid/gb/identifiers.rb,
lib/pubid/gb/identifiers/standard.rb
Overview
Chinese Standard (GB) flavor.
Covers national (GB), sector/industry (DB, QB, ZB, HB, JB, NY, YY, HJ, CJ, JG, MH, SL, DL, TB, TD, ...) and social-group (T/ORG) standards issued under the Chinese standards system. The mandate category is carried after a slash: T (recommended), Z (guideline), or omitted (mandatory).
Defined Under Namespace
Modules: Identifiers Classes: Builder, Identifier, Parser, Renderer
Constant Summary collapse
- PREFIXES =
Leading tokens a printed Chinese Standard identifier may start with. Used by relaton to route reference strings to this flavor. National "GB" comes first so PrefixesSupport's longest-match wins.
%w[ GB GB/T GB/Z DB DB/T DB/Z QB QB/T ZB ZB/T HB HB/T JB JB/T NY NY/T YY YY/T HJ HJ/T CJ CJ/T JG JG/T MH MH/T SL SL/T DL DL/T TB TB/T TD TD/T T/ ].freeze
Class Method Summary collapse
- .all_typed_stages ⇒ Object
-
.identifier_types ⇒ Array<Class>
Auto-discover concrete identifier types.
- .locate_stage(abbr) ⇒ Object
- .locate_type(code) ⇒ Object
-
.parse(identifier) ⇒ Pubid::Gb::Identifier
Parse a Chinese Standard identifier string.
Methods included from PrefixesSupport
Class Method Details
.all_typed_stages ⇒ Object
66 67 68 69 70 |
# File 'lib/pubid/gb.rb', line 66 def self.all_typed_stages @all_typed_stages ||= identifier_types.flat_map do |klass| klass.const_defined?(:TYPED_STAGES) ? klass.const_get(:TYPED_STAGES) : [] end end |
.identifier_types ⇒ Array<Class>
Auto-discover concrete identifier types.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pubid/gb.rb', line 55 def self.identifier_types @identifier_types ||= Identifiers.constants .filter_map do |c| Identifiers.const_get(c); rescue NameError; nil end .select { |c| c.is_a?(Class) && c.singleton_methods(false).include?(:type) } .select { |c| c.type.is_a?(Hash) } end |
.locate_stage(abbr) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/pubid/gb.rb', line 76 def self.locate_stage(abbr) abbr_str = abbr.to_s.upcase all_typed_stages.find do |s| s.abbr.any? do |a| a.to_s.upcase == abbr_str end end end |
.locate_type(code) ⇒ Object
72 73 74 |
# File 'lib/pubid/gb.rb', line 72 def self.locate_type(code) identifier_types.find { |t| t.type[:key].to_s == code.to_s } end |
.parse(identifier) ⇒ Pubid::Gb::Identifier
Parse a Chinese Standard identifier string.
46 47 48 |
# File 'lib/pubid/gb.rb', line 46 def self.parse(identifier) Identifier.parse(identifier) end |