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[
  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.

Parameters:

  • edition (String)
  • docnumber (String, NilClass)
  • language (Array<String>)
  • script (Arrra<String>)
  • docstatus (RelatonBib::DocumentStatus, NilClass)
  • type (String, NilClass)
  • formattedref (RelatonBib::FormattedRef, NilClass)
  • version (RelatonBib::BibliographicItem::Version, NilClass)
  • biblionote (Array<RelatonBib::BiblioNote>)
  • series (Array<RelatonBib::Series>)
  • medium (RelatonBib::Medium, NilClas)
  • place (Array<String>)
  • extent (Array<Relaton::BibItemLocality>)
  • accesslocation (Array<String>)
  • classification (RelatonBib::Classification, NilClass)
  • validity (RelatonBib:Validity, NilClass)
  • docid (Array<RelatonBib::DocumentIdentifier>)
  • structuredidentifier (RelatonIsoBib::StructuredIdentifier)
  • titles (Array<Hash>)
  • editorialgroup (Hash, RelatonIsoBib::EditorialGroup)
  • ics (Array<Hash>)
  • dates (Array<Hash>)
  • abstract (Array<Hash>)
  • contributors (Array<Hash>)
  • copyright (Hash)
  • link (Array<Hash, RelatonIsoBib::TypedUri>)
  • relations (Array<Hash>)
  • workgrpup (Hash)

    a customizable set of options

  • technical_committee (Hash)

    a customizable set of options

  • entity (Hash)

    a customizable set of options

  • owner (Hash)

    a customizable set of options

Raises:

  • (ArgumentError)


124
125
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
164
165
166
167
168
169
170
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 124

def initialize(**args)
  if args[:type] && !TYPES.include?(args[:type])
    raise ArgumentError, "invalid type: #{args[:type]}"
  end

  args.fetch(:language, []).each do |lang|
    unless %w[en fr].include? lang
      raise ArgumentError, "invalid language: #{lang}"
    end
  end

  args.fetch(:script, []).each do |scr|
    raise ArgumentError, "invalid script: #{scr}" unless scr == "Latn"
  end

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

  @structuredidentifier = args[:structuredidentifier]

  @title = args.fetch(:titles, []).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

  @doctype = args[:type]
  @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)

Returns:

  • (String, NilClass)


37
38
39
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 37

def doctype
  @doctype
end

#editorialgroupRelatonIsoBib::EditorialGroup (readonly)



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

def editorialgroup
  @editorialgroup
end

#icsArray<RelatonIsoBib::Ics> (readonly)



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

def ics
  @ics
end

#structuredidentifierRelatonIsoBib::StructuredIdentifier (readonly)



31
32
33
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 31

def structuredidentifier
  @structuredidentifier
end

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

Parameters:

  • lang (String) (defaults to: nil)

    language code Iso639

Returns:



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

Instance Method Details

#disable_id_attributeObject

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



174
175
176
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 174

def disable_id_attribute
  @id_attribute = false
end

#to_all_partsObject

remove title part components and abstract



179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 179

def to_all_parts
  me = DeepClone.clone(self)
  me.disable_id_attribute
  @relations << RelatonBib::DocumentRelation.new(
    type: "partOf", bibitem: me,
  )
  @title.delete_if { |t| t.type == "title-part" }
  @abstract = []
  @docidentifier.each(&:remove_part)
  @docidentifier.each(&:all_parts)
  @structuredidentifier.remove_part
  @structuredidentifier.all_parts
  @all_parts = true
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
  @relations << RelatonBib::DocumentRelation.new(type: "instance", bibitem: me)
  @abstract = []
  @dates = []
  @docidentifier.each &:remove_date
  @structuredidentifier.remove_date
  @id&.sub! /-[12]\d\d\d/, ""
end

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

Returns:

  • (String)


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

def to_xml(builder = nil, **opts, &block)
  if opts[:note] && !opts[:note].empty?
    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
        editorialgroup&.to_xml b
        ics.each { |i| i.to_xml b }
        structuredidentifier.to_xml b
      end
    end
  end
end

#url(type = :src) ⇒ String

Parameters:

  • type (Symbol) (defaults to: :src)

    type of url, can be :src/:obp/:rss

Returns:

  • (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