Class: RelatonBib::Edition

Inherits:
Object show all
Defined in:
lib/relaton_bib/edition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, number: nil) ⇒ Edition

Initialize edition.

Parameters:

  • content (String, Integer, Float)

    edition

  • number (String, Integer, Float, nil) (defaults to: nil)

    number



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

def initialize(content:, number: nil)
  @content = content.to_s
  @number = number&.to_s
end

Instance Attribute Details

#contentString (readonly)

Returns edition.

Returns:

  • (String)

    edition



4
5
6
# File 'lib/relaton_bib/edition.rb', line 4

def content
  @content
end

#numberString? (readonly)

Returns number.

Returns:

  • (String, nil)

    number



7
8
9
# File 'lib/relaton_bib/edition.rb', line 7

def number
  @number
end

Instance Method Details

#to_asciibib(prefix = "") ⇒ String

Render edition as AsciiBib.

Parameters:

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

    prefix

Returns:

  • (String)

    edition as AsciiBib.



48
49
50
51
52
53
# File 'lib/relaton_bib/edition.rb', line 48

def to_asciibib(prefix = "")
  pref = prefix.empty? ? "edition" : "#{prefix}.edition"
  out = "#{pref}.content:: #{content}\n"
  out += "#{pref}.number:: #{number}\n" if number
  out
end

#to_hashHash

Return edition as hash.

Returns:

  • (Hash)

    edition as hash.



35
36
37
38
39
# File 'lib/relaton_bib/edition.rb', line 35

def to_hash
  hash = { "content" => content }
  hash["number"] = number if number
  hash
end

#to_xml(builder) ⇒ Object

Render edition as XML.

Parameters:

  • builder (Nokogiri::XML::Builder)

    XML builder



25
26
27
28
# File 'lib/relaton_bib/edition.rb', line 25

def to_xml(builder)
  node = builder.edition(content)
  node[:number] = number if number
end