Class: RelatonBib::DocumentIdentifier
- Defined in:
- lib/relaton_bib/document_identifier.rb
Overview
Document identifier.
Instance Attribute Summary collapse
- #id ⇒ String readonly
- #primary ⇒ Object readonly
- #scope ⇒ String, NilClass readonly
- #type ⇒ String, NilClass readonly
Instance Method Summary collapse
- #all_parts ⇒ Object
-
#initialize(id:, type: nil, scope: nil, primary: false) ⇒ DocumentIdentifier
constructor
A new instance of DocumentIdentifier.
- #remove_date ⇒ Object
-
#remove_part ⇒ Object
in docid manipulations, assume ISO as the default: id-part:year.
- #to_asciibib(prefix = "", count = 1) ⇒ String
- #to_hash ⇒ Hash
-
#to_xml(**opts) ⇒ Object
Add docidentifier xml element.
Constructor Details
#initialize(id:, type: nil, scope: nil, primary: false) ⇒ DocumentIdentifier
Returns a new instance of DocumentIdentifier.
17 18 19 20 21 22 |
# File 'lib/relaton_bib/document_identifier.rb', line 17 def initialize(id:, type: nil, scope: nil, primary: false) @id = id @type = type @scope = scope @primary = primary end |
Instance Attribute Details
#id ⇒ String (readonly)
5 6 7 |
# File 'lib/relaton_bib/document_identifier.rb', line 5 def id @id end |
#primary ⇒ Object (readonly)
11 12 13 |
# File 'lib/relaton_bib/document_identifier.rb', line 11 def primary @primary end |
#scope ⇒ String, NilClass (readonly)
8 9 10 |
# File 'lib/relaton_bib/document_identifier.rb', line 8 def scope @scope end |
#type ⇒ String, NilClass (readonly)
8 9 10 |
# File 'lib/relaton_bib/document_identifier.rb', line 8 def type @type end |
Instance Method Details
#all_parts ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/relaton_bib/document_identifier.rb', line 42 def all_parts if type == "URN" @id.sub!(%r{^(urn:iec:std(?::[^:]*){4}).*}, '\1:ser') else @id += " (all parts)" end end |
#remove_date ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/relaton_bib/document_identifier.rb', line 33 def remove_date case @type when "Chinese Standard" then @id.sub!(/-[12]\d\d\d/, "") when "ISO", "IEC", "BSI" then @id.sub!(/:[12]\d\d\d/, "") when "URN" @id.sub!(/^(urn:iec:std:[^:]+:[^:]+:)[^:]*/, '\1') end end |
#remove_part ⇒ Object
in docid manipulations, assume ISO as the default: id-part:year
25 26 27 28 29 30 31 |
# File 'lib/relaton_bib/document_identifier.rb', line 25 def remove_part case @type when "Chinese Standard" then @id.sub!(/\.\d+/, "") when "ISO", "IEC", "BSI" then @id.sub!(/-[^:]+/, "") when "URN" then remove_urn_part end end |
#to_asciibib(prefix = "", count = 1) ⇒ String
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/relaton_bib/document_identifier.rb', line 79 def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize pref = prefix.empty? ? prefix : "#{prefix}." return "#{pref}docid:: #{id}\n" unless type || scope out = count > 1 ? "#{pref}docid::\n" : "" out += "#{pref}docid.type:: #{type}\n" if type out += "#{pref}docid.scope:: #{scope}\n" if scope out += "#{pref}docid.primary:: #{primary}\n" if primary out + "#{pref}docid.id:: #{id}\n" end |
#to_hash ⇒ Hash
68 69 70 71 72 73 74 |
# File 'lib/relaton_bib/document_identifier.rb', line 68 def to_hash hash = { "id" => id } hash["type"] = type if type hash["scope"] = scope if scope hash["primary"] = primary if primary hash end |
#to_xml(**opts) ⇒ Object
Add docidentifier xml element
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/relaton_bib/document_identifier.rb', line 56 def to_xml(**opts) # rubocop:disable Metrics/AbcSize lid = if type == "URN" && opts[:lang] id.sub %r{(?<=:)(?:\w{2},)*?(#{opts[:lang]})(?:,\w{2})*}, '\1' else id end element = opts[:builder].docidentifier lid element[:type] = type if type element[:scope] = scope if scope element[:primary] = primary if primary end |