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.



28
29
30
# File 'lib/relaton_bib/document_relation_collection.rb', line 28

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

#to_asciibib(prefix = "") ⇒ String

Parameters:

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

Returns:

  • (String)


34
35
36
37
38
39
40
41
42
# File 'lib/relaton_bib/document_relation_collection.rb', line 34

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