Class: RelatonBib::BibliographicItem

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_bib/bibliographic_item.rb,
lib/relaton_bib/biblio_version.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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ BibliographicItem

Returns a new instance of BibliographicItem.

Parameters:



210
211
212
213
214
215
216
217
218
219
220
221
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/relaton_bib/bibliographic_item.rb', line 210

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

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

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

  @contributors = (args[:contributors] || []).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[:roles])
    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]
  @relations      = DocRelationCollection.new(args[:relations] || [])
  @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, [])
  @extent         = args[:extent] || []
  @accesslocation = args.fetch :accesslocation, []
  @classification = args[: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 127

#accesslocationArray<Strig> (readonly)

Returns:

  • (Array<Strig>)


152
153
154
# File 'lib/relaton_bib/bibliographic_item.rb', line 152

def accesslocation
  @accesslocation
end

#biblionoteArray<RelatonBib::BiblioNote>, NilClass (readonly)

Returns:



116
117
118
# File 'lib/relaton_bib/bibliographic_item.rb', line 116

def biblionote
  @biblionote
end

#classificationRelaton::Classification, NilClass (readonly)

Returns:

  • (Relaton::Classification, NilClass)


155
156
157
# File 'lib/relaton_bib/bibliographic_item.rb', line 155

def classification
  @classification
end

#contributorsArray<RelatonBib::ContributionInfo> (readonly)

Returns:



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

def contributors
  @contributors
end


134
135
136
# File 'lib/relaton_bib/bibliographic_item.rb', line 134

def copyright
  @copyright
end

#datesArray<RelatonBib::BibliographicDate> (readonly)

Returns:



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

def dates
  @dates
end

#docidentifierArray<RelatonBib::DocumentIdentifier> (readonly)

Returns:



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

def docidentifier
  @docidentifier
end

#docnumberString (readonly)

Returns docnumber.

Returns:

  • (String)

    docnumber



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

def docnumber
  @docnumber
end

#editionString, NillClass (readonly)

Returns:

  • (String, NillClass)


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

def edition
  @edition
end

#extentArray<RelatonBib::BibItemLocality> (readonly)

Returns:



149
150
151
# File 'lib/relaton_bib/bibliographic_item.rb', line 149

def extent
  @extent
end

#fetchedDate (readonly)

Returns:

  • (Date)


161
162
163
# File 'lib/relaton_bib/bibliographic_item.rb', line 161

def fetched
  @fetched
end

#formattedrefRelatonBib::FormattedRef (readonly)



125
126
127
# File 'lib/relaton_bib/bibliographic_item.rb', line 125

def formattedref
  @formattedref
end

#idString (readonly)

Returns:

  • (String)


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

def id
  @id
end

#languageArray<String> (readonly)

Returns language Iso639 code.

Returns:

  • (Array<String>)

    language Iso639 code



119
120
121
# File 'lib/relaton_bib/bibliographic_item.rb', line 119

def language
  @language
end

Returns:



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

def link
  @link
end

#mediumRelatonBib::Medium, NilClass (readonly)

Returns:



143
144
145
# File 'lib/relaton_bib/bibliographic_item.rb', line 143

def medium
  @medium
end

#placeArray<String> (readonly)

Returns:

  • (Array<String>)


146
147
148
# File 'lib/relaton_bib/bibliographic_item.rb', line 146

def place
  @place
end

#relationsRelatonBib::DocRelationCollection (readonly)



137
138
139
# File 'lib/relaton_bib/bibliographic_item.rb', line 137

def relations
  @relations
end

#scriptArray<String> (readonly)

Returns script Iso15924 code.

Returns:

  • (Array<String>)

    script Iso15924 code



122
123
124
# File 'lib/relaton_bib/bibliographic_item.rb', line 122

def script
  @script
end

#seriesArray<RelatonBib::Series> (readonly)

Returns:



140
141
142
# File 'lib/relaton_bib/bibliographic_item.rb', line 140

def series
  @series
end

#statusRelatonBib::DocumentStatus, NilClass (readonly)

Returns:



131
132
133
# File 'lib/relaton_bib/bibliographic_item.rb', line 131

def status
  @status
end

#titleArray<RelatonBib::TypedTitleString> (readonly)

Returns:



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

def title
  @title
end

#typeString (readonly)

Returns:

  • (String)


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

def type
  @type
end

#validityRelatonBib:Validity, NilClass (readonly)

Returns:

  • (RelatonBib:Validity, NilClass)


158
159
160
# File 'lib/relaton_bib/bibliographic_item.rb', line 158

def validity
  @validity
end

#versionRelatonBib::BibliongraphicItem::Version (readonly)

Returns:

  • (RelatonBib::BibliongraphicItem::Version)


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

def version
  @version
end

Instance Method Details

#makeid(id, attribute) ⇒ Object



277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/relaton_bib/bibliographic_item.rb', line 277

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

#shortref(identifier, **opts) ⇒ String

Returns:

  • (String)


292
293
294
295
296
297
298
299
300
# File 'lib/relaton_bib/bibliographic_item.rb', line 292

def shortref(identifier, **opts)
  pubdate = dates.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_xml(builder = nil, **opts, &block) ⇒ String

Parameters:

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

    (nil)

Returns:

  • (String)


304
305
306
307
308
309
310
311
312
# File 'lib/relaton_bib/bibliographic_item.rb', line 304

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