Class: RelatonBib::DocumentIdentifier
- Defined in:
- lib/relaton_bib/document_identifier.rb
Overview
Document identifier.
Instance Attribute Summary collapse
- #id ⇒ String readonly
- #scope ⇒ String, NilClass readonly
- #type ⇒ String, NilClass readonly
Instance Method Summary collapse
- #all_parts ⇒ Object
-
#initialize(id:, type: nil, scope: nil) ⇒ 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(builder) ⇒ Object
Add docidentifier xml element.
Constructor Details
#initialize(id:, type: nil, scope: nil) ⇒ DocumentIdentifier
Returns a new instance of DocumentIdentifier.
13 14 15 16 17 |
# File 'lib/relaton_bib/document_identifier.rb', line 13 def initialize(id:, type: nil, scope: nil) @id = id @type = type @scope = scope end |
Instance Attribute Details
#id ⇒ String (readonly)
5 6 7 |
# File 'lib/relaton_bib/document_identifier.rb', line 5 def id @id 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
36 37 38 |
# File 'lib/relaton_bib/document_identifier.rb', line 36 def all_parts @id += " (all parts)" end |
#remove_date ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/relaton_bib/document_identifier.rb', line 28 def remove_date case @type when "Chinese Standard" then @id.sub!(/-[12]\d\d\d/, "") else @id.sub!(/:[12]\d\d\d/, "") end end |
#remove_part ⇒ Object
in docid manipulations, assume ISO as the default: id-part:year
20 21 22 23 24 25 26 |
# File 'lib/relaton_bib/document_identifier.rb', line 20 def remove_part case @type when "Chinese Standard" then @id.sub!(/\.\d+/, "") else @id.sub!(/-\d+/, "") end end |
#to_asciibib(prefix = "", count = 1) ⇒ String
62 63 64 65 66 67 68 69 |
# File 'lib/relaton_bib/document_identifier.rb', line 62 def to_asciibib(prefix = "", count = 1) pref = prefix.empty? ? prefix : prefix + "." 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.id:: #{id}\n" out end |
#to_hash ⇒ Hash
52 53 54 55 56 57 |
# File 'lib/relaton_bib/document_identifier.rb', line 52 def to_hash hash = { "id" => id } hash["type"] = type if type hash["scope"] = scope if scope hash end |
#to_xml(builder) ⇒ Object
Add docidentifier xml element
45 46 47 48 49 |
# File 'lib/relaton_bib/document_identifier.rb', line 45 def to_xml(builder) element = builder.docidentifier id element[:type] = type if type element[:scope] = scope if scope end |