Class: RelatonBib::Contact

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

Overview

Contact class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, value:) ⇒ Contact

Returns a new instance of Contact.

Parameters:

  • type (String)

    allowed “phone”, “email” or “uri”

  • value (String)


83
84
85
86
# File 'lib/relaton_bib/contributor.rb', line 83

def initialize(type:, value:)
  @type  = type
  @value = value
end

Instance Attribute Details

#typeString (readonly)

Returns allowed “phone”, “email” or “uri”.

Returns:

  • (String)

    allowed “phone”, “email” or “uri”



76
77
78
# File 'lib/relaton_bib/contributor.rb', line 76

def type
  @type
end

#valueString (readonly)

Returns:

  • (String)


79
80
81
# File 'lib/relaton_bib/contributor.rb', line 79

def value
  @value
end

Instance Method Details

#to_asciibib(prefix = "", count = 1) ⇒ string

Parameters:

  • prefix (String) (defaults to: "")
  • count (Integer) (defaults to: 1)

    number of contacts

Returns:

  • (string)


101
102
103
104
105
106
107
# File 'lib/relaton_bib/contributor.rb', line 101

def to_asciibib(prefix = "", count = 1)
  pref = prefix.empty? ? prefix : prefix + "."
  out = count > 1 ? "#{pref}contact::\n" : ""
  out += "#{pref}contact.type:: #{type}\n"
  out += "#{pref}contact.value:: #{value}\n"
  out
end

#to_hashHash

Returns:

  • (Hash)


94
95
96
# File 'lib/relaton_bib/contributor.rb', line 94

def to_hash
  { "type" => type, "value" => value }
end

#to_xml(doc) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Document)


89
90
91
# File 'lib/relaton_bib/contributor.rb', line 89

def to_xml(doc)
  doc.send type, value
end