Class: RelatonIsoBib::StructuredIdentifier

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_iso_bib/structured_identifier.rb

Overview

Document structured identifier.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ StructuredIdentifier

Returns a new instance of StructuredIdentifier.

Parameters:

  • tc_document_number (Integer, NilClass)
  • project_number (String)
  • part (String, NilClass)
  • subpart (String, NilClass)
  • type (String, NilClass)


24
25
26
27
28
29
30
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 24

def initialize(**args)
  @tc_document_number = args[:tc_document_number]
  @project_number = args[:project_number]
  @part = args[:part]
  @subpart = args[:subpart]
  @type = args[:type]
end

Instance Attribute Details

#partInteger, NilClass (readonly)

Returns:

  • (Integer, NilClass)


11
12
13
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 11

def part
  @part
end

#project_numberString (readonly)

Returns:

  • (String)


8
9
10
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 8

def project_number
  @project_number
end

#subpartInteger, NilClass (readonly)

Returns:

  • (Integer, NilClass)


14
15
16
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 14

def subpart
  @subpart
end

#tc_document_numberInteger, NilClass (readonly)

Returns:

  • (Integer, NilClass)


5
6
7
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 5

def tc_document_number
  @tc_document_number
end

#typeString, NilClass (readonly)

Returns:

  • (String, NilClass)


17
18
19
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 17

def type
  @type
end

Instance Method Details

#all_partsObject



52
53
54
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 52

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

#idObject



56
57
58
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 56

def id
  project_number
end

#presence?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 102

def presence?
  true
end

#remove_dateObject



44
45
46
47
48
49
50
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 44

def remove_date
  if @type == "Chinese Standard"
    @project_number.sub!(/-[12]\d\d\d/, "")
  else
    @project_number.sub!(/:[12]\d\d\d/, "")
  end
end

#remove_partObject

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



33
34
35
36
37
38
39
40
41
42
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 33

def remove_part
  @part_number = nil
  @subpart_number = nil
  @project_number = case @type
                    when "Chinese Standard"
                      @project_number.sub(/\.\d+/, "")
                    else
                      @project_number = @project_number.sub(/-\d+/, "")
                    end
end

#to_asciibib(prefix = "") ⇒ String

Parameters:

  • prefix (String) (defaults to: "")

Returns:

  • (String)


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 86

def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
  pref = prefix.empty? ? prefix : prefix + "."
  pref += "structured_identifier"
  out = ""
  if tc_document_number
    out += "#{pref}.tc_document_number:: #{tc_document_number}\n"
  end
  if project_number
    out += "#{pref}.project_number:: #{project_number}\n"
  end
  out += "#{pref}.part:: #{part}\n" if part
  out += "#{pref}.subpart:: #{subpart}\n" if subpart
  out += "#{pref}.type:: #{type}\n" if type
  out
end

#to_hashHash

Returns:

  • (Hash)


74
75
76
77
78
79
80
81
82
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 74

def to_hash
  hash = {}
  hash["tc_document_number"] = tc_document_number if tc_document_number
  hash["project_number"] = project_number if project_number
  hash["part"] = part if part
  hash["subpart"] = subpart if subpart
  hash["type"] = type if type
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


61
62
63
64
65
66
67
68
69
70
71
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 61

def to_xml(builder)
  xml = builder.structuredidentifier do
    pn = builder.send "project-number", project_number
    pn[:part] = part if part
    pn[:subpart] = subpart if subpart
    if tc_document_number
      builder.send "tc-document-number", tc_document_number
    end
  end
  xml[:type] = type if type
end