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)


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

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

Instance Attribute Details

#subtypeString? (readonly)

Returns:

  • (String, nil)


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

def subtype
  @subtype
end

#typeString (readonly)

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

Returns:

  • (String)

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



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

def type
  @type
end

#valueString (readonly)

Returns:

  • (String)


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

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



109
110
111
# File 'lib/relaton_bib/contributor.rb', line 109

def ==(other)
  type == other.type && subtype == other.subtype && value == other.value
end

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

Parameters:

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

    number of contacts

Returns:

  • (string)


129
130
131
132
133
134
135
# File 'lib/relaton_bib/contributor.rb', line 129

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)


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

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

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Document)


114
115
116
117
# File 'lib/relaton_bib/contributor.rb', line 114

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