Class: RelatonBib::StructuredIdentifier

Inherits:
Object
  • Object
show all
Includes:
RelatonBib
Defined in:
lib/relaton_bib/structured_identifier.rb

Constant Summary

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RelatonBib

array, format_date, grammar_hash, parse_date, parse_yaml

Constructor Details

#initialize(docnumber:, **args) ⇒ StructuredIdentifier

Returns a new instance of StructuredIdentifier.

Parameters:

  • docnumber (String)
  • args (Hash)

Options Hash (**args):

  • :type (String, nil)
  • :agency (Array<String>)
  • :class (Stirng, nil)
  • :partnumber (String, nil)
  • :edition (String, nil)
  • :version (String, nil)
  • :supplementtype (String, nil)
  • :supplementnumber (String, nil)
  • :language (String, nil)
  • :year (String, nil)


85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/relaton_bib/structured_identifier.rb', line 85

def initialize(docnumber:, **args)
  @type = args[:type]
  @agency = args[:agency]
  @klass = args[:class]
  @docnumber = docnumber
  @partnumber = args[:partnumber]
  @edition = args[:edition]
  @version = args[:version]
  @supplementtype = args[:supplementtype]
  @supplementnumber = args[:supplementnumber]
  @language = args[:language]
  @year = args[:year]
end

Instance Attribute Details

#agencyArray<String> (readonly)

Returns:



65
66
67
# File 'lib/relaton_bib/structured_identifier.rb', line 65

def agency
  @agency
end

#docnumberString (readonly)

Returns:

  • (String)


62
63
64
# File 'lib/relaton_bib/structured_identifier.rb', line 62

def docnumber
  @docnumber
end

#editionString? (readonly)

Returns:

  • (String, nil)


68
69
70
# File 'lib/relaton_bib/structured_identifier.rb', line 68

def edition
  @edition
end

#klassString? (readonly)

Returns:

  • (String, nil)


68
69
70
# File 'lib/relaton_bib/structured_identifier.rb', line 68

def klass
  @klass
end

#languageString? (readonly)

Returns:

  • (String, nil)


68
69
70
# File 'lib/relaton_bib/structured_identifier.rb', line 68

def language
  @language
end

#partnumberString? (readonly)

Returns:

  • (String, nil)


68
69
70
# File 'lib/relaton_bib/structured_identifier.rb', line 68

def partnumber
  @partnumber
end

#supplementnumberString? (readonly)

Returns:

  • (String, nil)


68
69
70
# File 'lib/relaton_bib/structured_identifier.rb', line 68

def supplementnumber
  @supplementnumber
end

#supplementtypeString? (readonly)

Returns:

  • (String, nil)


68
69
70
# File 'lib/relaton_bib/structured_identifier.rb', line 68

def supplementtype
  @supplementtype
end

#typeString? (readonly)

Returns:

  • (String, nil)


68
69
70
# File 'lib/relaton_bib/structured_identifier.rb', line 68

def type
  @type
end

#versionString? (readonly)

Returns:

  • (String, nil)


68
69
70
# File 'lib/relaton_bib/structured_identifier.rb', line 68

def version
  @version
end

#yearString? (readonly)

Returns:

  • (String, nil)


68
69
70
# File 'lib/relaton_bib/structured_identifier.rb', line 68

def year
  @year
end

Instance Method Details

#all_partsObject



169
170
171
# File 'lib/relaton_bib/structured_identifier.rb', line 169

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

#remove_dateObject



154
155
156
157
158
159
160
161
# File 'lib/relaton_bib/structured_identifier.rb', line 154

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

#remove_partObject

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



164
165
166
167
# File 'lib/relaton_bib/structured_identifier.rb', line 164

def remove_part
  @partnumber = nil
  @docnumber = @docnumber.sub(/-\d+/, "")
end

#to_asciibib(prefix) ⇒ String

Parameters:

  • prefix (String)

Returns:

  • (String)


137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/relaton_bib/structured_identifier.rb', line 137

def to_asciibib(prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength,Metrics/PerceivedComplexity
  out = "#{prefix}.docnumber:: #{docnumber}\n"
  agency.each { |a| out += "#{prefix}.agency:: #{a}\n" }
  out += "#{prefix}.type:: #{type}\n" if type
  out += "#{prefix}.class:: #{klass}\n" if klass
  out += "#{prefix}.partnumber:: #{partnumber}\n" if partnumber
  out += "#{prefix}.edition:: #{edition}\n" if edition
  out += "#{prefix}.version:: #{version}\n" if version
  out += "#{prefix}.supplementtype:: #{supplementtype}\n" if supplementtype
  if supplementnumber
    out += "#{prefix}.supplementnumber:: #{supplementnumber}\n"
  end
  out += "#{prefix}.language:: #{language}\n" if language
  out += "#{prefix}.year:: #{year}\n" if year
  out
end

#to_hashHash

Returns:

  • (Hash)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/relaton_bib/structured_identifier.rb', line 119

def to_hash
  hash = { "docnumber" => docnumber }
  hash["type"] = type if type
  hash["agency"] = single_element_array agency if agency&.any?
  hash["class"] = klass if klass
  hash["partnumber"] = partnumber if partnumber
  hash["edition"] = edition if edition
  hash["version"] = version if version
  hash["supplementtype"] = supplementtype if supplementtype
  hash["supplementnumber"] = supplementnumber if supplementnumber
  hash["language"] = language if language
  hash["year"] = year if year
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/relaton_bib/structured_identifier.rb', line 102

def to_xml(builder)
  xml = builder.structuredidentifier do |b|
    agency&.each { |a| b.agency a }
    b.class_ klass if klass
    b.docnumber docnumber
    b.partnumber partnumber if partnumber
    b.edition edition if edition
    b.version version if version
    b.supplementtype supplementtype if supplementtype
    b.supplementnumber supplementnumber if supplementnumber
    b.language language if language
    b.year year if year
  end
  xml[:type] = type if type
end