Class: RelatonBib::TypedTitleStringCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/relaton_bib/typed_title_string.rb

Instance Method Summary collapse

Constructor Details

#initialize(title = []) ⇒ TypedTitleStringCollection

Returns a new instance of TypedTitleStringCollection.

Parameters:



9
10
11
12
13
# File 'lib/relaton_bib/typed_title_string.rb', line 9

def initialize(title = [])
  @array = (title || []).map do |t|
    t.is_a?(Hash) ? TypedTitleString.new(**t) : t
  end
end

Instance Method Details

#+(tcoll) ⇒ RelatonBib::TypedTitleStringCollection



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

def +(tcoll)
  TypedTitleStringCollection.new titles + tcoll.titles
end

#<<(title) ⇒ self

Parameters:

Returns:

  • (self)


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

def <<(title)
  titles << title
  self
end

#delete_title_part!Object



24
25
26
# File 'lib/relaton_bib/typed_title_string.rb', line 24

def delete_title_part!
  titles.delete_if { |t| t.type == "title-part" }
end

#lang(lang = nil) ⇒ RelatonIsoBib::TypedTitleStringCollection

Parameters:

  • lang (String, nil) (defaults to: nil)

    language code Iso639

Returns:

  • (RelatonIsoBib::TypedTitleStringCollection)


17
18
19
20
21
22
# File 'lib/relaton_bib/typed_title_string.rb', line 17

def lang(lang = nil)
  if lang
    TypedTitleStringCollection.new select_lang(lang)
  else self
  end
end

#select(&block) ⇒ RelatonBib::TypedTitleStringCollection



29
30
31
# File 'lib/relaton_bib/typed_title_string.rb', line 29

def select(&block)
  TypedTitleStringCollection.new titles.select(&block)
end

#titlesObject



52
53
54
# File 'lib/relaton_bib/typed_title_string.rb', line 52

def titles
  @array
end

#to_bibtex(item) ⇒ Object

Add main title ot bibtex entry

Parameters:

  • item (BibTeX::Entry)

    bibtex entry



74
75
76
77
78
79
# File 'lib/relaton_bib/typed_title_string.rb', line 74

def to_bibtex(item)
  tl = titles.detect { |t| t.type == "main" } || titles.first
  return unless tl

  item.title = tl.title.content
end

#to_hashObject



65
66
67
# File 'lib/relaton_bib/typed_title_string.rb', line 65

def to_hash
  @array.map(&:to_hash)
end

#to_xml(**opts) ⇒ Object

Parameters:

  • opts (Hash)

Options Hash (**opts):

  • XML (Nokogiri::XML::Builder)

    builder

  • :lang (String, Symbol)

    language



59
60
61
62
63
# File 'lib/relaton_bib/typed_title_string.rb', line 59

def to_xml(**opts)
  tl = select_lang(opts[:lang])
  tl = titles unless tl.any?
  tl.each { |t| opts[:builder].title { t.to_xml opts[:builder] } }
end