Class: RelatonBib::TypedTitleStringCollection
- Extended by:
- Forwardable
- Defined in:
- lib/relaton_bib/typed_title_string.rb
Instance Method Summary collapse
- #+(tcoll) ⇒ RelatonBib::TypedTitleStringCollection
- #<<(title) ⇒ self
- #delete_title_part! ⇒ Object
-
#initialize(title = []) ⇒ TypedTitleStringCollection
constructor
A new instance of TypedTitleStringCollection.
- #lang(lang = nil) ⇒ RelatonIsoBib::TypedTitleStringCollection
- #select(&block) ⇒ RelatonBib::TypedTitleStringCollection
- #titles ⇒ Object
-
#to_bibtex(item) ⇒ Object
Add main title ot bibtex entry.
- #to_hash ⇒ Object
- #to_xml(**opts) ⇒ Object
Constructor Details
#initialize(title = []) ⇒ TypedTitleStringCollection
Returns a new instance of TypedTitleStringCollection.
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
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
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 |
#titles ⇒ Object
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
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_hash ⇒ Object
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
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 |