Class: Obp::Access::Urn

Inherits:
Object
  • Object
show all
Defined in:
lib/obp/access/urn.rb

Constant Summary collapse

DOC_TYPE_SEGMENTS =
%w[ts tr pas guide iwa].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#baseObject (readonly)

Returns the value of attribute base.



6
7
8
# File 'lib/obp/access/urn.rb', line 6

def base
  @base
end

#languageObject (readonly)

Returns the value of attribute language.



6
7
8
# File 'lib/obp/access/urn.rb', line 6

def language
  @language
end

#rawObject (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_numberObject

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_typeObject



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_segmentObject

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

#editionObject



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

#hashObject



28
29
30
# File 'lib/obp/access/urn.rb', line 28

def hash
  raw.hash
end

#originatorObject

Originator segment: "iso", "iec", "itu", ...



37
38
39
# File 'lib/obp/access/urn.rb', line 37

def originator
  parts[2]
end

#partsObject



32
33
34
# File 'lib/obp/access/urn.rb', line 32

def parts
  @parts ||= raw.split(":")
end

#safeObject



15
16
17
# File 'lib/obp/access/urn.rb', line 15

def safe
  @safe ||= raw.tr(":", "-")
end

#to_sObject



19
20
21
# File 'lib/obp/access/urn.rb', line 19

def to_s
  raw
end

#versionObject



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