Class: RelatonBib::StructuredIdentifier
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/structured_identifier.rb
Constant Summary
Constants included from RelatonBib
Instance Attribute Summary collapse
- #agency ⇒ Array<String> readonly
- #docnumber ⇒ String readonly
- #edition ⇒ String, NilClass readonly
- #klass ⇒ String, NilClass readonly
- #language ⇒ String, NilClass readonly
- #partnumber ⇒ String, NilClass readonly
- #supplementnumber ⇒ String, NilClass readonly
- #supplementtype ⇒ String, NilClass readonly
- #type ⇒ String, NilClass readonly
- #version ⇒ String, NilClass readonly
- #year ⇒ String, NilClass readonly
Instance Method Summary collapse
- #all_parts ⇒ Object
-
#initialize(docnumber:, **args) ⇒ StructuredIdentifier
constructor
A new instance of StructuredIdentifier.
- #remove_date ⇒ Object
-
#remove_part ⇒ Object
in docid manipulations, assume ISO as the default: id-part:year.
- #to_asciibib(prefix) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(builder) ⇒ Object
Methods included from RelatonBib
Constructor Details
#initialize(docnumber:, **args) ⇒ StructuredIdentifier
Returns a new instance of StructuredIdentifier.
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/relaton_bib/structured_identifier.rb', line 83 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
#agency ⇒ Array<String> (readonly)
64 65 66 |
# File 'lib/relaton_bib/structured_identifier.rb', line 64 def agency @agency end |
#docnumber ⇒ String (readonly)
61 62 63 |
# File 'lib/relaton_bib/structured_identifier.rb', line 61 def docnumber @docnumber end |
#edition ⇒ String, NilClass (readonly)
67 68 69 |
# File 'lib/relaton_bib/structured_identifier.rb', line 67 def edition @edition end |
#klass ⇒ String, NilClass (readonly)
67 68 69 |
# File 'lib/relaton_bib/structured_identifier.rb', line 67 def klass @klass end |
#language ⇒ String, NilClass (readonly)
67 68 69 |
# File 'lib/relaton_bib/structured_identifier.rb', line 67 def language @language end |
#partnumber ⇒ String, NilClass (readonly)
67 68 69 |
# File 'lib/relaton_bib/structured_identifier.rb', line 67 def partnumber @partnumber end |
#supplementnumber ⇒ String, NilClass (readonly)
67 68 69 |
# File 'lib/relaton_bib/structured_identifier.rb', line 67 def supplementnumber @supplementnumber end |
#supplementtype ⇒ String, NilClass (readonly)
67 68 69 |
# File 'lib/relaton_bib/structured_identifier.rb', line 67 def supplementtype @supplementtype end |
#type ⇒ String, NilClass (readonly)
67 68 69 |
# File 'lib/relaton_bib/structured_identifier.rb', line 67 def type @type end |
#version ⇒ String, NilClass (readonly)
67 68 69 |
# File 'lib/relaton_bib/structured_identifier.rb', line 67 def version @version end |
#year ⇒ String, NilClass (readonly)
67 68 69 |
# File 'lib/relaton_bib/structured_identifier.rb', line 67 def year @year end |
Instance Method Details
#all_parts ⇒ Object
167 168 169 |
# File 'lib/relaton_bib/structured_identifier.rb', line 167 def all_parts @docnumber = @docnumber + " (all parts)" end |
#remove_date ⇒ Object
152 153 154 155 156 157 158 159 |
# File 'lib/relaton_bib/structured_identifier.rb', line 152 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_part ⇒ Object
in docid manipulations, assume ISO as the default: id-part:year
162 163 164 165 |
# File 'lib/relaton_bib/structured_identifier.rb', line 162 def remove_part @partnumber = nil @docnumber = @docnumber.sub(/-\d+/, "") end |
#to_asciibib(prefix) ⇒ String
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/relaton_bib/structured_identifier.rb', line 135 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_hash ⇒ Hash
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/relaton_bib/structured_identifier.rb', line 117 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
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/relaton_bib/structured_identifier.rb', line 100 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 |