Class: RelatonIsoBib::IsoBibliographicItem

Inherits:
RelatonBib::BibliographicItem
  • Object
show all
Defined in:
lib/relaton_iso_bib/iso_bibliographic_item.rb

Overview

Bibliographic item.

Constant Summary collapse

TYPES =
%w[
  standard
  international-standard technical-specification technical-report
  publicly-available-specification international-workshop-agreement guide
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ IsoBibliographicItem

Returns a new instance of IsoBibliographicItem.

Raises:

  • (ArgumentError)


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 126

def initialize(**args)
  check_doctype args[:doctype]
  # check_language args.fetch(:language, [])
  # check_script args.fetch(:script, [])

  super_args = args.select do |k|
    i[id docnumber language script docstatus date abstract contributor
       edition version relation biblionote series medium place copyright
       link fetched docid formattedref extent accesslocation classification
       validity].include? k
  end
  super super_args

  @type = args[:type] || "standard"

  @title = args.fetch(:title, []).reduce([]) do |a, t|
    if t.is_a? Hash
      a + typed_titles(t)
    else
      a << t
    end
  end

  if args[:editorialgroup]
    @editorialgroup = if args[:editorialgroup].is_a?(Hash)
                        EditorialGroup.new(args[:editorialgroup])
                      else args[:editorialgroup]
                      end
  end

  @structuredidentifier = args[:structuredidentifier]
  @doctype ||= args[:doctype]
  @ics = args.fetch(:ics, []).map { |i| i.is_a?(Hash) ? Ics.new(i) : i }
  # @link = args.fetch(:link, []).map do |s|
  #   s.is_a?(Hash) ? RelatonBib::TypedUri.new(s) : s
  # end
  @id_attribute = true
end

Instance Attribute Details

#doctypeString, NilClass (readonly)



39
40
41
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 39

def doctype
  @doctype
end

#editorialgroupRelatonIsoBib::EditorialGroup (readonly)



42
43
44
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 42

def editorialgroup
  @editorialgroup
end

#icsArray<RelatonIsoBib::Ics> (readonly)



45
46
47
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 45

def ics
  @ics
end

#structuredidentifierRelatonIsoBib::StructuredIdentifier (readonly)



33
34
35
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 33

def structuredidentifier
  @structuredidentifier
end

#title(lang: nil) ⇒ Array<RelatonIsoBib::TypedTitleString> (readonly)



# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 35


Instance Method Details

#disable_id_attributeObject

rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity



167
168
169
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 167

def disable_id_attribute
  @id_attribute = false
end

#to_all_partsObject

remove title part components and abstract



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 172

def to_all_parts
  me = DeepClone.clone(self)
  me.disable_id_attribute
  @relation << RelatonBib::DocumentRelation.new(
    type: "instance", bibitem: me,
  )
  @language.each do |l|
    @title.delete_if { |t| t.type == "title-part" }
    ttl = @title.select { |t| t.type != "main" && t.title.language.include?(l) }
    tm_en = ttl.map { |t| t.title.content }.join " – "
    @title.detect { |t| t.type == "main" && t.title.language.include?(l) }&.title&.content = tm_en
  end
  @abstract = []
  @docidentifier.each(&:remove_part)
  @docidentifier.each(&:all_parts)
  @structuredidentifier.remove_part
  @structuredidentifier.all_parts
  @docidentifier.each &:remove_date
  @structuredidentifier&.remove_date
  @all_parts = true
end

#to_hashHash



253
254
255
256
257
258
259
260
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 253

def to_hash
  hash = super
  hash["editorialgroup"] = editorialgroup.to_hash if editorialgroup
  hash["ics"] = single_element_array(ics) if ics&.any?
  hash["structuredidentifier"] = structuredidentifier.to_hash if structuredidentifier
  hash["type"] = doctype if doctype
  hash
end

#to_most_recent_referenceObject

convert ISO:yyyy reference to reference to most recent instance of reference, removing date-specific infomration: date of publication, abstracts. Make dated reference Instance relation of the redacated document



198
199
200
201
202
203
204
205
206
207
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 198

def to_most_recent_reference
  me = DeepClone.clone(self)
  me.disable_id_attribute
  @relation << RelatonBib::DocumentRelation.new(type: "instance", bibitem: me)
  @abstract = []
  @date = []
  @docidentifier.each &:remove_date
  @structuredidentifier&.remove_date
  @id&.sub! /-[12]\d\d\d/, ""
end

#to_xml(builder = nil, **opts, &block) ⇒ String



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 226

def to_xml(builder = nil, **opts, &block)
  if opts[:note]&.any?
    opts.fetch(:note, []).each do |n|
      @biblionote << RelatonBib::BiblioNote.new(
        content: n[:text], type: n[:type], format: "text/plain",
      )
    end
  end
  super builder, **opts do |b|
    if opts[:bibdata]
      b.ext do
        b.doctype doctype if doctype
        # GB renders gbcommittee elements istead of an editorialgroup element.
        if respond_to? :committee
          committee&.to_xml b
        else
          editorialgroup&.to_xml b
        end
        ics.each { |i| i.to_xml b }
        structuredidentifier&.to_xml b
        yield b if block_given?
      end
    end
  end
end

#url(type = :src) ⇒ String



221
222
223
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 221

def url(type = :src)
  @link.detect { |s| s.type == type.to_s }.content.to_s
end