Class: Pubid::Jis::Identifier

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

Overview

Base class for every JIS identifier AND the flavor's parse/create entry point — mirrors Pubid::Iso::Identifier. Concrete identifiers under Pubid::Jis::Identifiers descend from this class, so a parsed JIS id is an instance of Pubid::Jis::Identifier.

Direct Known Subclasses

SingleIdentifier

Constant Summary collapse

JIS_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:jis:japanese-industrial-standard" =>
    "Pubid::Jis::Identifiers::JapaneseIndustrialStandard",
  "pubid:jis:standard" => "Pubid::Jis::Identifiers::Standard",
  "pubid:jis:technical-report" =>
    "Pubid::Jis::Identifiers::TechnicalReport",
  "pubid:jis:technical-specification" =>
    "Pubid::Jis::Identifiers::TechnicalSpecification",
  "pubid:jis:amendment" => "Pubid::Jis::Identifiers::Amendment",
  "pubid:jis:corrigendum" => "Pubid::Jis::Identifiers::Corrigendum",
  "pubid:jis:explanation" => "Pubid::Jis::Identifiers::Explanation",
}.freeze
PUBLISHER =

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

"JIS"

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_edition, #mr_number, #mr_part, #mr_subpart, #mr_supplement_suffix, #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

Class Method Details

.parse(identifier) ⇒ Identifier

Parse a JIS identifier string into an identifier object

Parameters:

  • identifier (String)

    The JIS identifier string to parse

Returns:

  • (Identifier)

    The appropriate identifier object

Raises:

  • (RuntimeError)

    If parsing fails



179
180
181
182
183
184
# File 'lib/pubid/jis/identifier.rb', line 179

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

Instance Method Details

#==(other) ⇒ Object

Comparison with all_parts logic When either identifier has all_parts=true, compare only series and number



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/pubid/jis/identifier.rb', line 96

def ==(other)
  return false unless other.is_a?(Identifier)

  if all_parts? || other.all_parts?
    # Compare only series and number, ignore year, parts, all_parts
    return series == other.series && number == other.number
  end

  # Normal full comparison
  series == other.series &&
    number == other.number &&
    (parts || []) == (other.parts || []) &&
    year == other.year &&
    language == other.language &&
    all_parts? == other.all_parts? &&
    reaffirmed? == other.reaffirmed? &&
    symbol == other.symbol
end

#all_parts?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/pubid/jis/identifier.rb', line 65

def all_parts?
  all_parts == true
end

#codeObject

The rendered document code, e.g. "B 0205-1" (series, number, parts). A convenience for rendering; the underlying data is the flat series/number/parts attributes.



88
89
90
91
92
# File 'lib/pubid/jis/identifier.rb', line 88

def code
  result = "#{series} #{number}"
  result += parts.map { |p| "-#{p}" }.join if parts&.any?
  result
end

#mr_all_partsObject



166
167
168
169
170
# File 'lib/pubid/jis/identifier.rb', line 166

def mr_all_parts
  return nil unless all_parts?

  "all-parts"
end

#mr_languagesObject



160
161
162
163
164
# File 'lib/pubid/jis/identifier.rb', line 160

def mr_languages
  return nil unless language

  "(#{language})"
end

#mr_number_with_partObject



140
141
142
143
144
145
146
147
148
# File 'lib/pubid/jis/identifier.rb', line 140

def mr_number_with_part
  segments = []
  segments << series.to_s.downcase if series
  segments << number.to_s if number
  parts&.each { |p| segments << p.to_s }
  return nil if segments.empty?

  segments.join("-")
end

#mr_publisherObject

JIS exposes its publisher as the PUBLISHER constant rather than the inherited publisher attribute, so the generic mr_publisher returns nil. Without this override every JIS id would lose its "JIS." prefix. Lowercased to match the all-lowercase MR convention.



124
125
126
# File 'lib/pubid/jis/identifier.rb', line 124

def mr_publisher
  PUBLISHER.downcase
end

#mr_typeObject

JIS stores its identity across series (division letter A–Z), number (string, may have leading zeros), and parts (multi-level). The generic mr_number_with_part only knows about number/part/subpart, so without these overrides every JIS id would collapse onto its document number and drop the division letter (issue #142). Lowercased to match the all-lowercase MR convention.



134
135
136
137
138
# File 'lib/pubid/jis/identifier.rb', line 134

def mr_type
  return nil unless respond_to?(:type_prefix)

  type_prefix&.downcase
end

#mr_yearObject

JIS stores the year as a bare integer (not a Components::Date), so the inherited mr_year (which reads date) returns nil. Emit it directly, including the reaffirmation marker so JIS X:2019 and JIS X:2019R stay distinct in MR.



154
155
156
157
158
# File 'lib/pubid/jis/identifier.rb', line 154

def mr_year
  return nil unless year

  year_with_reaffirmation.to_s
end

#reaffirmed?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/pubid/jis/identifier.rb', line 69

def reaffirmed?
  reaffirmed == true
end

#symbol_suffixObject

Render the trailing " SYMBOL[ ]" clause, or "" when absent.



79
80
81
82
83
# File 'lib/pubid/jis/identifier.rb', line 79

def symbol_suffix
  return "" if symbol.nil?

  symbol.empty? ? " SYMBOL" : " SYMBOL #{symbol}"
end

#to_s(**opts) ⇒ Object

Basic string representation. Delegates to renderer.



116
117
118
# File 'lib/pubid/jis/identifier.rb', line 116

def to_s(**opts)
  render(format: :human, **opts)
end

#year_with_reaffirmationObject

Render a year with its reaffirmation marker, e.g. "2019R".



74
75
76
# File 'lib/pubid/jis/identifier.rb', line 74

def year_with_reaffirmation
  "#{year}#{'R' if reaffirmed?}"
end