Class: RelatonW3c::PubId
- Inherits:
-
Object
- Object
- RelatonW3c::PubId
- Defined in:
- lib/relaton_w3c/pubid.rb
Constant Summary collapse
- PARTS =
%i[code stage type year date suff].freeze
Class Method Summary collapse
-
.parse(docnumber) ⇒ RelatonW3c::PubId
Parse document identifier.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compare document identifiers against Hash ID representation.
-
#initialize(**parts) ⇒ PubId
constructor
A new instance of PubId.
-
#to_hash ⇒ Hash
Convert docidentifier identifier to hash.
Constructor Details
Class Method Details
.parse(docnumber) ⇒ RelatonW3c::PubId
Parse document identifier.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/relaton_w3c/pubid.rb', line 18 def self.parse(docnumber) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength %r{ (?:^|/)(?:(?:(?<stage>WD|CRD|CR|PR|PER|REC|SPSD|OBSL|RET)|(?<type>D?NOTE|TR))[\s/-])? (?<code>\w+(?:[+-][\w.]+)*?) (?:-(?<year>(?:18|19|20)\d{2}))? (?:-(?<date>\d{8}|\d{6}|\d{4}))? (?:/(?<suff>\w+))?(?:$|/) }xi =~ docnumber entry = { code: code } entry[:stage] = stage if stage entry[:type] = type if type && type != "TR" entry[:year] = year if year entry[:date] = date if date entry[:suff] = suff if suff new(**entry) end |
Instance Method Details
#==(other) ⇒ Boolean
Compare document identifiers against Hash ID representation.
42 43 44 45 46 |
# File 'lib/relaton_w3c/pubid.rb', line 42 def ==(other) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity other[:code].casecmp?(code) && other[:stage] == stage && other[:type] == type && (year.nil? || other[:year] == year) && (date.nil? || other[:date] == date) && (suff.nil? || other[:suff]&.casecmp?(suff)) end |
#to_hash ⇒ Hash
Convert docidentifier identifier to hash.
53 54 55 |
# File 'lib/relaton_w3c/pubid.rb', line 53 def to_hash PARTS.each_with_object({}) { |part, hash| hash[part] = send part if send part } end |