Class: RelatonBib::DocumentType

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, abbreviation: nil) ⇒ DocumentType

Initialize a DocumentType.

Parameters:

  • type (String)

    document type

  • abbreviation (String, nil) (defaults to: nil)

    type abbreviation



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

def initialize(type:, abbreviation: nil)
  @type = type
  @abbreviation = abbreviation
end

Instance Attribute Details

#abbreviationObject (readonly)

Returns the value of attribute abbreviation.



3
4
5
# File 'lib/relaton_bib/document_type.rb', line 3

def abbreviation
  @abbreviation
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/relaton_bib/document_type.rb', line 3

def type
  @type
end

Instance Method Details

#to_asciibib(prefix = "") ⇒ String

Asciibib representation of the document type.

Parameters:

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

    prefix

Returns:

  • (String)

    AsciiBib representation



44
45
46
47
48
49
50
# File 'lib/relaton_bib/document_type.rb', line 44

def to_asciibib(prefix = "")
  pref = prefix.empty? ? prefix : "#{prefix}."
  pref += "doctype."
  out = "#{pref}type:: #{@type}\n"
  out += "#{pref}abbreviation:: #{@abbreviation}\n" if @abbreviation
  out
end

#to_hashHash

Hash representation of the document type.

Returns:

  • (Hash)


31
32
33
34
35
# File 'lib/relaton_bib/document_type.rb', line 31

def to_hash
  hash = { "type" => @type }
  hash["abbreviation"] = @abbreviation if @abbreviation
  hash
end

#to_xml(builder) ⇒ Object

Build XML representation of the document type.

Parameters:

  • builder (Nokogiri::XML::Builder)

    XML builder



21
22
23
24
# File 'lib/relaton_bib/document_type.rb', line 21

def to_xml(builder)
  xml = builder.doctype @type
  xml[:abbreviation] = @abbreviation if @abbreviation
end