Class: RelatonBib::DocRelationCollection

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

Overview

Document relation collection

Instance Method Summary collapse

Constructor Details

#initialize(relation) ⇒ DocRelationCollection

Returns a new instance of DocRelationCollection.

Parameters:

Options Hash (relation):



20
21
22
# File 'lib/relaton_bib/document_relation_collection.rb', line 20

def initialize(relation)
  @array = relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(**r) : r }
end

Instance Method Details

#replacesRelatonBib::DocRelationCollection

TODO:

We don’t have replace type anymore. Suppose we should update this method or delete it.



43
44
45
# File 'lib/relaton_bib/document_relation_collection.rb', line 43

def replaces
  DocRelationCollection.new(@array.select { |r| r.type == "replace" })
end

#select(&block) ⇒ RelatonBib::DocRelationCollection

Returns new DocumentRelationCollection with selected relations.

Examples:

Select relations with type “obsoletes”

relations.select { |r| r.type == "obsoletes" }
#=> <RelatonBib::DocRelationCollection:0x00007f9a0191d5f0 @array=[...]>

Returns:



34
35
36
37
# File 'lib/relaton_bib/document_relation_collection.rb', line 34

def select(&block)
  arr = @array.select(&block)
  self.class.new arr
end

#to_asciibib(prefix = "") ⇒ String

Parameters:

  • prefix (String) (defaults to: "")

Returns:

  • (String)


49
50
51
52
53
54
55
56
57
# File 'lib/relaton_bib/document_relation_collection.rb', line 49

def to_asciibib(prefix = "")
  pref = prefix.empty? ? "relation" : "#{prefix}.relation"
  out = ""
  @array.each do |r|
    out += size > 1 ? "#{pref}::\n" : ""
    out += r.to_asciibib pref
  end
  out
end