Class: Obp::Access::Urn
- Inherits:
-
Object
- Object
- Obp::Access::Urn
- Defined in:
- lib/obp/access/urn.rb
Constant Summary collapse
- DOC_TYPE_SEGMENTS =
%w[ts tr pas guide iwa].freeze
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#language ⇒ Object
readonly
Returns the value of attribute language.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#doc_number ⇒ Object
Document number, including part number when present.
- #doc_type ⇒ Object
-
#doc_type_segment ⇒ Object
Document type segment if present ("ts", "tr", ...), else nil.
- #edition ⇒ Object
- #hash ⇒ Object
-
#initialize(raw) ⇒ Urn
constructor
A new instance of Urn.
-
#originator ⇒ Object
Originator segment: "iso", "iec", "itu", ...
- #parts ⇒ Object
- #safe ⇒ Object
- #to_s ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(raw) ⇒ Urn
Returns a new instance of Urn.
8 9 10 11 12 13 |
# File 'lib/obp/access/urn.rb', line 8 def initialize(raw) @raw = raw parts = raw.split(":") @language = parts.last @base = parts[0...-1].join(":") end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
6 7 8 |
# File 'lib/obp/access/urn.rb', line 6 def base @base end |
#language ⇒ Object (readonly)
Returns the value of attribute language.
6 7 8 |
# File 'lib/obp/access/urn.rb', line 6 def language @language end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
6 7 8 |
# File 'lib/obp/access/urn.rb', line 6 def raw @raw end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
23 24 25 |
# File 'lib/obp/access/urn.rb', line 23 def ==(other) other.is_a?(self.class) && raw == other.raw end |
#doc_number ⇒ Object
Document number, including part number when present. "iso:std:iso:80000:-12:ed-2:v1:en" → "80000-12"
49 50 51 52 53 |
# File 'lib/obp/access/urn.rb', line 49 def doc_number identifier_segments .reject { |s| DOC_TYPE_SEGMENTS.include?(s) } .join end |
#doc_type ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/obp/access/urn.rb', line 65 def doc_type case doc_type_segment when "ts" then "TS" when "tr" then "TR" when "pas" then "PAS" when "guide" then "Guide" when "iwa" then "IWA" else "IS" end end |
#doc_type_segment ⇒ Object
Document type segment if present ("ts", "tr", ...), else nil
42 43 44 45 |
# File 'lib/obp/access/urn.rb', line 42 def doc_type_segment segments = identifier_segments segments.find { |s| DOC_TYPE_SEGMENTS.include?(s) } end |
#edition ⇒ Object
55 56 57 58 |
# File 'lib/obp/access/urn.rb', line 55 def edition segment = parts.find { |p| p.start_with?("ed-") } segment&.delete_prefix("ed-") end |
#hash ⇒ Object
28 29 30 |
# File 'lib/obp/access/urn.rb', line 28 def hash raw.hash end |
#originator ⇒ Object
Originator segment: "iso", "iec", "itu", ...
37 38 39 |
# File 'lib/obp/access/urn.rb', line 37 def originator parts[2] end |
#parts ⇒ Object
32 33 34 |
# File 'lib/obp/access/urn.rb', line 32 def parts @parts ||= raw.split(":") end |
#safe ⇒ Object
15 16 17 |
# File 'lib/obp/access/urn.rb', line 15 def safe @safe ||= raw.tr(":", "-") end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/obp/access/urn.rb', line 19 def to_s raw end |
#version ⇒ Object
60 61 62 63 |
# File 'lib/obp/access/urn.rb', line 60 def version segment = parts.find { |p| p.match?(/\Av\d+\z/) } segment&.delete_prefix("v") end |