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:, subtype: nil) ⇒ Contact

Returns a new instance of Contact.

Parameters:

  • type (String)

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

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

    i.e. “fax”, “mobile”, “landline” for “phone” or “work”, “personal” for “uri” type

  • value (String)


97
98
99
100
101
# File 'lib/relaton_bib/contributor.rb', line 97

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

Instance Attribute Details

#subtypeString? (readonly)

Returns:

  • (String, nil)


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

def subtype
  @subtype
end

#typeString (readonly)

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

Returns:

  • (String)

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



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

def type
  @type
end

#valueString (readonly)

Returns:

  • (String)


91
92
93
# File 'lib/relaton_bib/contributor.rb', line 91

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)


119
120
121
122
123
124
125
# File 'lib/relaton_bib/contributor.rb', line 119

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

#to_hashHash

Returns:

  • (Hash)


110
111
112
113
114
# File 'lib/relaton_bib/contributor.rb', line 110

def to_hash
  hash = { type => value }
  hash["type"] = subtype if subtype
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Document)


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

def to_xml(builder)
  node = builder.send type, value
  node["type"] = subtype if subtype
end