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
# 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] || [])
  @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

#to_xmlString

Returns:

  • (String)


212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/iso_bib_item/bibliographic_item.rb', line 212

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 }
      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 }
      status&.to_xml xml
      series.each { |s| s.to_xml xml } if series
    end
  end.doc.root.to_xml
end