Class: RelatonBib::DocumentIdentifier
- Defined in:
- lib/relaton_bib/document_identifier.rb
Overview
Document identifier.
Instance Attribute Summary collapse
- #id ⇒ String readonly
- #type ⇒ String, NilClass readonly
Instance Method Summary collapse
- #all_parts ⇒ Object
-
#initialize(id:, type: 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_hash ⇒ Hash
-
#to_xml(builder) ⇒ Object
Add docidentifier xml element.
Constructor Details
#initialize(id:, type: nil) ⇒ DocumentIdentifier
Returns a new instance of DocumentIdentifier.
12 13 14 15 |
# File 'lib/relaton_bib/document_identifier.rb', line 12 def initialize(id:, type: nil) @id = id @type = type end |
Instance Attribute Details
#id ⇒ String (readonly)
5 6 7 |
# File 'lib/relaton_bib/document_identifier.rb', line 5 def id @id 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
34 35 36 |
# File 'lib/relaton_bib/document_identifier.rb', line 34 def all_parts @id += " (all parts)" end |
#remove_date ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/relaton_bib/document_identifier.rb', line 26 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
18 19 20 21 22 23 24 |
# File 'lib/relaton_bib/document_identifier.rb', line 18 def remove_part case @type when "Chinese Standard" then @id.sub!(/\.\d+/, "") else @id.sub!(/-\d+/, "") end end |
#to_hash ⇒ Hash
49 50 51 52 53 |
# File 'lib/relaton_bib/document_identifier.rb', line 49 def to_hash hash = { "id" => id } hash["type"] = type if type hash end |
#to_xml(builder) ⇒ Object
Add docidentifier xml element
43 44 45 46 |
# File 'lib/relaton_bib/document_identifier.rb', line 43 def to_xml(builder) element = builder.docidentifier id element[:type] = type if type end |