Class: RelatonBib::BibliographicItem::Version

Inherits:
Object
  • Object
show all
Includes:
RelatonBib
Defined in:
lib/relaton_bib/biblio_version.rb

Constant Summary

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RelatonBib

parse_date

Constructor Details

#initialize(revision_date = nil, draft = []) ⇒ Version

Returns a new instance of Version.

Parameters:

  • revision_date (String, NilClass) (defaults to: nil)
  • draft (Array<String>) (defaults to: [])


15
16
17
18
# File 'lib/relaton_bib/biblio_version.rb', line 15

def initialize(revision_date = nil, draft = [])
  @revision_date = revision_date
  @draft         = draft
end

Instance Attribute Details

#draftArray<String> (readonly)

Returns:



11
12
13
# File 'lib/relaton_bib/biblio_version.rb', line 11

def draft
  @draft
end

#revision_dateString, NilClass (readonly)

Returns:

  • (String, NilClass)


8
9
10
# File 'lib/relaton_bib/biblio_version.rb', line 8

def revision_date
  @revision_date
end

Instance Method Details

#to_asciibib(prefix = "") ⇒ String

Parameters:

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

Returns:

  • (String)


38
39
40
41
42
43
44
45
46
# File 'lib/relaton_bib/biblio_version.rb', line 38

def to_asciibib(prefix = "")
  pref = prefix.empty? ? prefix : prefix + "."
  out = ""
  if revision_date
    out += "#{pref}version.revision_date:: #{revision_date}\n"
  end
  draft&.each { |d| out += "#{pref}version.draft:: #{d}\n" }
  out
end

#to_hashHash

Returns:

  • (Hash)


29
30
31
32
33
34
# File 'lib/relaton_bib/biblio_version.rb', line 29

def to_hash
  hash = {}
  hash["revision_date"] = revision_date if revision_date
  hash["draft"] = single_element_array(draft) if draft&.any?
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


21
22
23
24
25
26
# File 'lib/relaton_bib/biblio_version.rb', line 21

def to_xml(builder)
  builder.version do
    builder.send("revision-date", revision_date) if revision_date
    draft.each { |d| builder.draft d }
  end
end