Class: IsoBibItem::BibliographicItem

Inherits:
Object
  • Object
show all
Defined in:
lib/iso_bib_item/bibliographic_item.rb

Overview

Bibliographic item

Direct Known Subclasses

IsoBibliographicItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ BibliographicItem

Returns a new instance of BibliographicItem.

Parameters:



170
171
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
# File 'lib/iso_bib_item/bibliographic_item.rb', line 170

def initialize(**args)
  @id            = args[:id]
  @title         = (args[:titles] || []).map { |t| FormattedString.new t }
  @docidentifier = args[:docid] || []
  @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
  @notes         = []
  @language      = args[:language]
  @script        = args[:script]
  @status        = args[:docstatus]
  @abstract      = (args[:abstract] || []).map do |a|
    a.is_a?(Hash) ? FormattedString.new(a) : a
  end
  @relations = DocRelationCollection.new(args[:relations] || [])
  if args[:copyright]
    @copyright = if args[:copyright].is_a?(Hash)
                   CopyrightAssociation.new args[:copyright]
                 else args[:copyright] end
  end
  @link = args[:link].map { |s| s.is_a?(Hash) ? TypedUri.new(s) : s }
  @series = args[:series]
  @fetched = args.fetch :fetched, Date.today
end

Instance Attribute Details

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

Parameters:

  • lang (String) (defaults to: nil)

    language code Iso639

Returns:



# File 'lib/iso_bib_item/bibliographic_item.rb', line 135

#contributorsArray<IsoBibItem::ContributionInfo> (readonly)



118
119
120
# File 'lib/iso_bib_item/bibliographic_item.rb', line 118

def contributors
  @contributors
end


142
143
144
# File 'lib/iso_bib_item/bibliographic_item.rb', line 142

def copyright
  @copyright
end

#datesArray<IsoBibItem::BibliographicDate> (readonly)



115
116
117
# File 'lib/iso_bib_item/bibliographic_item.rb', line 115

def dates
  @dates
end

#docidentifierArray<IsoBibItem::DocumentIdentifier> (readonly)



112
113
114
# File 'lib/iso_bib_item/bibliographic_item.rb', line 112

def docidentifier
  @docidentifier
end

#editionString (readonly)

Returns:

  • (String)


121
122
123
# File 'lib/iso_bib_item/bibliographic_item.rb', line 121

def edition
  @edition
end

#fetchedDate (readonly)

Returns:

  • (Date)


151
152
153
# File 'lib/iso_bib_item/bibliographic_item.rb', line 151

def fetched
  @fetched
end

#formatted_refIsoBibItem::FormattedString (readonly)



133
134
135
# File 'lib/iso_bib_item/bibliographic_item.rb', line 133

def formatted_ref
  @formatted_ref
end

#idString (readonly)

Returns:

  • (String)


100
101
102
# File 'lib/iso_bib_item/bibliographic_item.rb', line 100

def id
  @id
end

#languageArray<String> (readonly)

Returns language Iso639 code.

Returns:

  • (Array<String>)

    language Iso639 code



127
128
129
# File 'lib/iso_bib_item/bibliographic_item.rb', line 127

def language
  @language
end


106
107
108
# File 'lib/iso_bib_item/bibliographic_item.rb', line 106

def link
  @link
end

#notesArray<IsoBibItem::FormattedString> (readonly)



124
125
126
# File 'lib/iso_bib_item/bibliographic_item.rb', line 124

def notes
  @notes
end

#relationsIsoBibItem::DocRelationCollection (readonly)



145
146
147
# File 'lib/iso_bib_item/bibliographic_item.rb', line 145

def relations
  @relations
end

#scriptArray<String> (readonly)

Returns script Iso15924 code.

Returns:

  • (Array<String>)

    script Iso15924 code



130
131
132
# File 'lib/iso_bib_item/bibliographic_item.rb', line 130

def script
  @script
end

#seriesArray<IsoBibItem::Series> (readonly)



148
149
150
# File 'lib/iso_bib_item/bibliographic_item.rb', line 148

def series
  @series
end

#statusIsoBibItem::DocumentStatus (readonly)



139
140
141
# File 'lib/iso_bib_item/bibliographic_item.rb', line 139

def status
  @status
end

#titleArray<IsoBibItem::FormattedString> (readonly)



103
104
105
# File 'lib/iso_bib_item/bibliographic_item.rb', line 103

def title
  @title
end

#typeIsoBibItem::BibItemType (readonly)

Returns:

  • (IsoBibItem::BibItemType)


109
110
111
# File 'lib/iso_bib_item/bibliographic_item.rb', line 109

def type
  @type
end

Instance Method Details

#makeid(id, attribute, delim = '') ⇒ Object



214
215
216
217
218
219
220
221
222
223
# File 'lib/iso_bib_item/bibliographic_item.rb', line 214

def makeid(id, attribute, delim = '')
  return nil if attribute && !@id_attribute
  id = @docidentifier.reject { |i| i.type == "DOI" }[0] 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(/:/, "-")
  #if id.part_number&.size&.positive? then idstr += "-#{id.part_number}"
  idstr.strip
end

#shortref(identifier, **opts) ⇒ String

Returns:

  • (String)


226
227
228
229
230
231
232
233
234
# File 'lib/iso_bib_item/bibliographic_item.rb', line 226

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_xmlString

Returns:

  • (String)


239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/iso_bib_item/bibliographic_item.rb', line 239

def to_xml
  Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml|
    xml.bibitem(id: id) do
      xml.fetched fetched
      title.each { |t| xml.title { t.to_xml xml } }
      link.each { |s| s.to_xml xml }
      docidentifier.each { |di| di.to_xml xml }
      dates.each { |d| d.to_xml xml, full_date: true }
      contributors.each do |c|
        xml.contributor do
          c.role.each { |r| r.to_xml xml }
          c.to_xml xml
        end
      end
      language.each { |l| xml.language l }
      script.each { |s| xml.script s }
      abstract.each { |a| xml.abstract { a.to_xml(xml) } }
      status.to_xml xml if status
      copyright.to_xml xml if copyright
      relations.each { |r| r.to_xml xml }
      series.each { |s| s.to_xml xml } if series
    end
  end.doc.root.to_xml
end