Class: IsoBibItem::IsoBibliographicItem

Inherits:
BibliographicItem show all
Defined in:
lib/iso_bib_item/iso_bibliographic_item.rb

Overview

Bibliographic item.

Instance Attribute Summary collapse

Attributes inherited from BibliographicItem

#abstract, #contributors, #copyright, #dates, #formatted_ref, #language, #link, #notes, #relations, #script, #series

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ IsoBibliographicItem

Returns a new instance of IsoBibliographicItem.

Parameters:

  • docid (Hash{project_number=>Integer, part_number=>Integer}, IsoBibItem::IsoDocumentId)
  • titles (Array<Hash{title_intro=>String, title_main=>String, title_part=>String, language=>String, script=>String}>)
  • edition (String)
  • language (Array<String>)
  • script (Arrra<String>)
  • type (String)
  • docstatus (Hash{status=>String, stage=>String, substage=>String})
  • workgroup (Hash{name=>String, abbreviation=>String, url=>String, technical_committee=>Hash{name=>String, type=>String, number=>Integer}})
  • ics (Array<Hash{field=>Integer, group=>Integer, subgroup=>Integer}>)
  • dates (Array<Hash{type=>String, from=>String, to=>String}>)
  • abstract (Array<Hash{content=>String, language=>String, script=>String, type=>String}>)
  • contributors (Array<Hash{entity=>Hash{name=>String, url=>String, abbreviation=>String}, roles=>Array<String>}>)
  • copyright (Hash{owner=>Hash{name=>String, abbreviation=>String, url=>String}, form=>String, to=>String})
  • link (Array<Hash{type=>String, content=>String}, IsoBibItem::TypedUri>)
  • relations (Array<Hash{type=>String, identifier=>String}>)


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

def initialize(**args)
  super_args = args.select do |k|
    %i[
      id language script dates abstract contributors relations link
    ].include? k
  end
  super(super_args)
  @docidentifier = if args[:docid].is_a?(Hash)
                     IsoDocumentId.new(args[:docid])
                   else args[:docid] end
  @edition = args[:edition]
  @title   = args[:titles].map do |t|
    t.is_a?(Hash) ? IsoLocalizedTitle.new(t) : t
  end
  @type   = args[:type]
  @status = if args[:docstatus].is_a?(Hash)
              IsoDocumentStatus.new(args[:docstatus])
            else args[:docstatus] end
  if args[:workgroup]
    @workgroup = if args[:workgroup].is_a?(Hash)
                   IsoProjectGroup.new(args[:workgroup])
                 else args[:workgroup] end
  end
  @ics = args[:ics].map { |i| i.is_a?(Hash) ? Ics.new(i) : i }
  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 }
  @id_attribute = true
end

Instance Attribute Details

#docidentifierIsoBibItem::IsoDocumentId (readonly)



83
84
85
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 83

def docidentifier
  @docidentifier
end

#editionString (readonly)

Returns:

  • (String)


86
87
88
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 86

def edition
  @edition
end

#icsArray<IsoBibItem::Ics> (readonly)

Returns:



101
102
103
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 101

def ics
  @ics
end

#statusIsoBibItem::IsoDocumentStatus (readonly)



95
96
97
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 95

def status
  @status
end

#title(lang: nil) ⇒ IsoBibItem::IsoLocalizedTitle (readonly)

Parameters:

  • lang (String) (defaults to: nil)

    language code Iso639

Returns:



# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 88

#typeIsoBibItem::IsoDocumentType (readonly)

Returns:

  • (IsoBibItem::IsoDocumentType)


92
93
94
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 92

def type
  @type
end

#workgroupIsoBibItem::IsoProjectGroup (readonly)



98
99
100
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 98

def workgroup
  @workgroup
end

Instance Method Details

#disable_id_attributeObject



158
159
160
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 158

def disable_id_attribute
  @id_attribute = false
end

#shortref(**opts) ⇒ String

TODO:

need to add ISO/IEC/IEEE

Returns:

  • (String)


200
201
202
203
204
205
206
207
208
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 200

def shortref(**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

  "#{id(false, ' ')}#{year}"
end

#to_all_partsObject

remove title part components and abstract



163
164
165
166
167
168
169
170
171
172
173
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 163

def to_all_parts
  #me = Duplicate.duplicate(self)
  me = DeepClone.clone(self)
  me.disable_id_attribute
  @relations << DocumentRelation.new(type: "partOf", identifier: nil, url: nil, bibitem: me)

  @title.each(&:remove_part)
  @abstract = []
  @docidentifier.remove_part
  @all_parts = true
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



179
180
181
182
183
184
185
186
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 179

def to_most_recent_reference
  #me = Duplicate.duplicate(self)
  me = DeepClone.clone(self)
  me.disable_id_attribute
  @relations << DocumentRelation.new(type: "instance", identifier: nil, url: nil, bibitem: me)
  @abstract = []
  @dates = []
end

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

Returns:

  • (String)


217
218
219
220
221
222
223
224
225
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 217

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

#url(type = :src) ⇒ String

Parameters:

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

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

Returns:

  • (String)


212
213
214
# File 'lib/iso_bib_item/iso_bibliographic_item.rb', line 212

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