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.

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)
  • title (Array<Hash>)
  • editorialgroup (Hash, RelatonIsoBib::EditorialGroup, RelatonItu::EditorialGroup)
  • ics (Array<Hash>)
  • date (Array<Hash>)
  • abstract (Array<Hash>)
  • contributor (Array<Hash>)
  • copyright (Hash)
  • link (Array<Hash, RelatonBib::TypedUri>)
  • relation (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)


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
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 126

def initialize(**args)
  check_type args[:type]
  # 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.merge(type: "standard")
  super(super_args)

  @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[: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)


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)

Parameters:

  • lang (String) (defaults to: nil)

    language code Iso639

Returns:



# 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



165
166
167
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 165

def disable_id_attribute
  @id_attribute = false
end

#to_all_partsObject

remove title part components and abstract



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

def to_all_parts
  me = DeepClone.clone(self)
  me.disable_id_attribute
  @relation << RelatonBib::DocumentRelation.new(
    type: "partOf", 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
  @all_parts = true
end

#to_hashHash

Returns:

  • (Hash)


249
250
251
252
253
254
255
256
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 249

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



194
195
196
197
198
199
200
201
202
203
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 194

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

Returns:

  • (String)


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

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

Parameters:

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

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

Returns:

  • (String)


217
218
219
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 217

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