Class: RelatonBib::DocRelationCollection
- Extended by:
- Forwardable
- Defined in:
- lib/relaton_bib/document_relation_collection.rb
Overview
Document relation collection
Instance Method Summary collapse
-
#initialize(relation) ⇒ DocRelationCollection
constructor
A new instance of DocRelationCollection.
- #replaces ⇒ RelatonBib::DocRelationCollection
-
#select(&block) ⇒ RelatonBib::DocRelationCollection
Returns new DocumentRelationCollection with selected relations.
- #to_asciibib(prefix = "") ⇒ String
Constructor Details
#initialize(relation) ⇒ DocRelationCollection
Returns a new instance of DocRelationCollection.
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
#replaces ⇒ RelatonBib::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.
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
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 |