Class: RelatonBib::DocumentIdentifier

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_bib/document_identifier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, type: nil) ⇒ DocumentIdentifier

Returns a new instance of DocumentIdentifier.

Parameters:

  • id (String)
  • type (String, NilClass) (defaults to: nil)


23
24
25
26
# File 'lib/relaton_bib/document_identifier.rb', line 23

def initialize(id:, type: nil)
  @id   = id
  @type = type
end

Instance Attribute Details

#idString (readonly)

Returns:

  • (String)


16
17
18
# File 'lib/relaton_bib/document_identifier.rb', line 16

def id
  @id
end

#typeString, NilClass (readonly)

Returns:

  • (String, NilClass)


19
20
21
# File 'lib/relaton_bib/document_identifier.rb', line 19

def type
  @type
end

Instance Method Details

#all_partsObject



45
46
47
# File 'lib/relaton_bib/document_identifier.rb', line 45

def all_parts
  @id += " (all parts)"
end

#remove_dateObject



37
38
39
40
41
42
43
# File 'lib/relaton_bib/document_identifier.rb', line 37

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_partObject

in docid manipulations, assume ISO as the default: id-part:year



29
30
31
32
33
34
35
# File 'lib/relaton_bib/document_identifier.rb', line 29

def remove_part
  case @type
  when "Chinese Standard" then @id.sub!(/\.\d+/, "")
  else
    @id.sub!(/-\d+/, "")
  end
end

#to_xml(builder) ⇒ Object

Add docidentifier xml element

Parameters:

  • builder (Nokogiri::XML::Builder)


54
55
56
# File 'lib/relaton_bib/document_identifier.rb', line 54

def to_xml(builder)
  builder.docidentifier(id, type: type)
end