Class: RelatonBib::BibliographicItem

Inherits:
Object
  • Object
show all
Includes:
RelatonBib
Defined in:
lib/relaton_bib/biblio_version.rb,
lib/relaton_bib/bibliographic_item.rb

Overview

Bibliographic item

Defined Under Namespace

Classes: Version

Constant Summary collapse

TYPES =
%W[article book booklet conference manual proceedings presentation
thesis techreport standard unpublished map electronic\sresource
audiovisual film video broadcast graphic_work music patent
inbook incollection inproceedings journal].freeze

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RelatonBib

array, formattedref, hash_to_bib, localizedstring, localname, parse_date, symbolize, timestamp_hash

Constructor Details

#initialize(**args) ⇒ BibliographicItem

Returns a new instance of BibliographicItem.

Parameters:



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/relaton_bib/bibliographic_item.rb', line 172

def initialize(**args)
  if args[:type] && !TYPES.include?(args[:type])
    warn %{Document type "#{args[:type]}" is invalid.}
  end

  @title = (args[:title] || []).map do |t|
    t.is_a?(Hash) ? TypedTitleString.new(t) : t
  end

  @date = (args[:date] || []).map do |d|
    d.is_a?(Hash) ? BibliographicDate.new(d) : d
  end

  @contributor = (args[:contributor] || []).map do |c|
    if c.is_a? Hash
      e = c[:entity].is_a?(Hash) ? Organization.new(c[:entity]) : c[:entity]
      ContributionInfo.new(entity: e, role: c[:role])
    else c
    end
  end

  @abstract = (args[:abstract] || []).map do |a|
    a.is_a?(Hash) ? FormattedString.new(a) : a
  end

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

  @docidentifier  = args[:docid] || []
  @formattedref   = args[:formattedref] if title.empty?
  @id             = args[:id] || makeid(nil, false)
  @type           = args[:type]
  @docnumber      = args[:docnumber]
  @edition        = args[:edition]
  @version        = args[:version]
  @biblionote     = args.fetch :biblionote, []
  @language       = args.fetch :language, []
  @script         = args.fetch :script, []
  @status         = args[:docstatus]
  @relation       = DocRelationCollection.new(args[:relation] || [])
  @link           = args.fetch(:link, []).map { |s| s.is_a?(Hash) ? TypedUri.new(s) : s }
  @series         = args.fetch :series, []
  @medium         = args[:medium]
  @place          = args.fetch(:place, []).map { |pl| pl.is_a?(String) ? Place.new(name: pl) : pl }
  @extent         = args[:extent] || []
  @accesslocation = args.fetch :accesslocation, []
  @classification = args.fetch :classification, []
  @validity       = args[:validity]
  @fetched        = args.fetch :fetched, nil # , Date.today # we should pass the fetched arg from scrappers
end

Instance Attribute Details

#abstract(lang: nil) ⇒ RelatonBib::FormattedString+ (readonly)

Parameters:

  • lang (String) (defaults to: nil)

    language code Iso639

Returns:



# File 'lib/relaton_bib/bibliographic_item.rb', line 80

#accesslocationArray<Strig> (readonly)

Returns:

  • (Array<Strig>)


105
106
107
# File 'lib/relaton_bib/bibliographic_item.rb', line 105

def accesslocation
  @accesslocation
end

#biblionoteArray<RelatonBib::BiblioNote> (readonly)

Returns:



69
70
71
# File 'lib/relaton_bib/bibliographic_item.rb', line 69

def biblionote
  @biblionote
end

#classificationArray<Relaton::Classification> (readonly)

Returns:

  • (Array<Relaton::Classification>)


108
109
110
# File 'lib/relaton_bib/bibliographic_item.rb', line 108

def classification
  @classification
end

#contributorArray<RelatonBib::ContributionInfo> (readonly)

Returns:



60
61
62
# File 'lib/relaton_bib/bibliographic_item.rb', line 60

def contributor
  @contributor
end

Returns:



87
88
89
# File 'lib/relaton_bib/bibliographic_item.rb', line 87

def copyright
  @copyright
end

#dateArray<RelatonBib::BibliographicDate> (readonly)

Returns:



57
58
59
# File 'lib/relaton_bib/bibliographic_item.rb', line 57

def date
  @date
end

#docidentifierArray<RelatonBib::DocumentIdentifier> (readonly)

Returns:



51
52
53
# File 'lib/relaton_bib/bibliographic_item.rb', line 51

def docidentifier
  @docidentifier
end

#docnumberString, NilClass (readonly)

Returns docnumber.

Returns:

  • (String, NilClass)

    docnumber



54
55
56
# File 'lib/relaton_bib/bibliographic_item.rb', line 54

def docnumber
  @docnumber
end

#editionString, NillClass (readonly)

Returns:

  • (String, NillClass)


63
64
65
# File 'lib/relaton_bib/bibliographic_item.rb', line 63

def edition
  @edition
end

#extentArray<RelatonBib::BibItemLocality> (readonly)

Returns:



102
103
104
# File 'lib/relaton_bib/bibliographic_item.rb', line 102

def extent
  @extent
end

#fetchedDate (readonly)

Returns:

  • (Date)


114
115
116
# File 'lib/relaton_bib/bibliographic_item.rb', line 114

def fetched
  @fetched
end

#formattedrefRelatonBib::FormattedRef, NilClass (readonly)

Returns:



78
79
80
# File 'lib/relaton_bib/bibliographic_item.rb', line 78

def formattedref
  @formattedref
end

#idString, NilClass (readonly)

Returns:

  • (String, NilClass)


39
40
41
# File 'lib/relaton_bib/bibliographic_item.rb', line 39

def id
  @id
end

#languageArray<String> (readonly)

Returns language Iso639 code.

Returns:

  • (Array<String>)

    language Iso639 code



72
73
74
# File 'lib/relaton_bib/bibliographic_item.rb', line 72

def language
  @language
end

Returns:



45
46
47
# File 'lib/relaton_bib/bibliographic_item.rb', line 45

def link
  @link
end

#mediumRelatonBib::Medium, NilClass (readonly)

Returns:



96
97
98
# File 'lib/relaton_bib/bibliographic_item.rb', line 96

def medium
  @medium
end

#placeArray<RelatonBib::Place> (readonly)

Returns:



99
100
101
# File 'lib/relaton_bib/bibliographic_item.rb', line 99

def place
  @place
end

#relationRelatonBib::DocRelationCollection (readonly)



90
91
92
# File 'lib/relaton_bib/bibliographic_item.rb', line 90

def relation
  @relation
end

#scriptArray<String> (readonly)

Returns script Iso15924 code.

Returns:

  • (Array<String>)

    script Iso15924 code



75
76
77
# File 'lib/relaton_bib/bibliographic_item.rb', line 75

def script
  @script
end

#seriesArray<RelatonBib::Series> (readonly)

Returns:



93
94
95
# File 'lib/relaton_bib/bibliographic_item.rb', line 93

def series
  @series
end

#statusRelatonBib::DocumentStatus, NilClass (readonly)

Returns:



84
85
86
# File 'lib/relaton_bib/bibliographic_item.rb', line 84

def status
  @status
end

#titleArray<RelatonBib::TypedTitleString> (readonly)

Returns:



42
43
44
# File 'lib/relaton_bib/bibliographic_item.rb', line 42

def title
  @title
end

#typeString, NilClass (readonly)

Returns:

  • (String, NilClass)


48
49
50
# File 'lib/relaton_bib/bibliographic_item.rb', line 48

def type
  @type
end

#validityRelatonBib:Validity, NilClass (readonly)

Returns:

  • (RelatonBib:Validity, NilClass)


111
112
113
# File 'lib/relaton_bib/bibliographic_item.rb', line 111

def validity
  @validity
end

#versionRelatonBib::BibliongraphicItem::Version, NilClass (readonly)

Returns:

  • (RelatonBib::BibliongraphicItem::Version, NilClass)


66
67
68
# File 'lib/relaton_bib/bibliographic_item.rb', line 66

def version
  @version
end

Instance Method Details

#makeid(id, attribute) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/relaton_bib/bibliographic_item.rb', line 239

def makeid(id, attribute)
  return nil if attribute && !@id_attribute

  id ||= @docidentifier.reject { |i| i.type == "DOI" }[0]
  return unless id

  # contribs = publishers.map { |p| p&.entity&.abbreviation }.join '/'
  # idstr = "#{contribs}#{delim}#{id.project_number}"
  # idstr = id.project_number.to_s
  idstr = id.id.gsub(/:/, "-").gsub /\s/, ""
  # if id.part_number&.size&.positive? then idstr += "-#{id.part_number}"
  idstr.strip
end

#revdateString, NilClass

If revision_date exists then returns it else returns published date or nil

Returns:

  • (String, NilClass)


336
337
338
339
340
341
342
# File 'lib/relaton_bib/bibliographic_item.rb', line 336

def revdate
  @revdate ||= if version&.revision_date
                 version.revision_date
               else
                 date.detect { |d| d.type == "published" }&.on&.to_s
               end
end

#shortref(identifier, **opts) ⇒ String

Returns:

  • (String)


254
255
256
257
258
259
260
261
262
# File 'lib/relaton_bib/bibliographic_item.rb', line 254

def shortref(identifier, **opts)
  pubdate = date.select { |d| d.type == "published" }
  year = if opts[:no_year] || pubdate.empty? then ""
         else ":" + pubdate&.first&.on&.year.to_s
         end
  year += ": All Parts" if opts[:all_parts] || @all_parts

  "#{makeid(identifier, false)}#{year}"
end

#to_bibtex(bibtex = nil) ⇒ String

Parameters:

  • bibtex (BibTeX::Bibliography, NilClass) (defaults to: nil)

Returns:

  • (String)


311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/relaton_bib/bibliographic_item.rb', line 311

def to_bibtex(bibtex = nil)
  item = BibTeX::Entry.new
  item.type = bibtex_type
  item.key = id
  bibtex_title item
  item.edition = edition if edition
  bibtex_author item
  bibtex_contributor item
  item.address = place.first.name if place.any?
  bibtex_note item
  bibtex_relation item
  bibtex_extent item
  bibtex_date item
  bibtex_series item
  bibtex_classification item
  bibtex_docidentifier item
  item.timestamp = fetched.to_s if fetched
  bibtex_link item
  bibtex ||= BibTeX::Bibliography.new
  bibtex << item
  bibtex.to_s
end

#to_hashHash

Returns:

  • (Hash)


277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/relaton_bib/bibliographic_item.rb', line 277

def to_hash
  hash = {}
  hash["id"] = id if id
  hash["title"] = single_element_array(title) if title&.any?
  hash["link"] = single_element_array(link) if link&.any?
  hash["type"] = type if type
  hash["docid"] = single_element_array(docidentifier) if docidentifier&.any?
  hash["docnumber"] = docnumber if docnumber
  hash["date"] = single_element_array(date) if date&.any?
  hash["contributor"] = single_element_array(contributor) if contributor&.any?
  hash["edition"] = edition if edition
  hash["version"] = version.to_hash if version
  hash["revdate"] = revdate if revdate
  hash["biblionote"] = single_element_array(biblionote) if biblionote&.any?
  hash["language"] = single_element_array(language) if language&.any?
  hash["script"] = single_element_array(script) if script&.any?
  hash["formattedref"] = formattedref.to_hash if formattedref
  hash["abstract"] = single_element_array(abstract) if abstract&.any?
  hash["docstatus"] = status.to_hash if status
  hash["copyright"] = copyright.to_hash if copyright
  hash["relation"] = single_element_array(relation) if relation&.any?
  hash["series"] = single_element_array(series) if series&.any?
  hash["medium"] = medium.to_hash if medium
  hash["place"] = single_element_array(place) if place&.any?
  hash["extent"] = single_element_array(extent) if extent&.any?
  hash["accesslocation"] = single_element_array(accesslocation) if accesslocation&.any?
  hash["classification"] = single_element_array(classification) if classification&.any?
  hash["validity"] = validity.to_hash if validity
  hash["fetched"] = fetched.to_s if fetched
  hash
end

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

Parameters:

  • builder (Nokogiri::XML::Builder, NillClass) (defaults to: nil)

    (nil)

Returns:

  • (String)


266
267
268
269
270
271
272
273
274
# File 'lib/relaton_bib/bibliographic_item.rb', line 266

def to_xml(builder = nil, **opts, &block)
  if builder
    render_xml builder, **opts, &block
  else
    Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
      render_xml xml, **opts, &block
    end.doc.root.to_xml
  end
end