Class: RelatonBib::Contributor
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/contributor.rb
Overview
Contributor.
Direct Known Subclasses
Constant Summary
Constants included from RelatonBib
Instance Attribute Summary collapse
- #contact ⇒ Array<RelatonBib::Address, RelatonBib::Contact> readonly
- #uri ⇒ URI readonly
Instance Method Summary collapse
-
#initialize(url: nil, contact: []) ⇒ Contributor
constructor
A new instance of Contributor.
- #to_asciibib(prefix = "") ⇒ String
- #to_hash ⇒ Hash
- #to_xml(builder) ⇒ Object
-
#url ⇒ String
Returns url.
Methods included from RelatonBib
Constructor Details
#initialize(url: nil, contact: []) ⇒ Contributor
Returns a new instance of Contributor.
178 179 180 181 |
# File 'lib/relaton_bib/contributor.rb', line 178 def initialize(url: nil, contact: []) @uri = URI url if url @contact = contact end |
Instance Attribute Details
#contact ⇒ Array<RelatonBib::Address, RelatonBib::Contact> (readonly)
174 175 176 |
# File 'lib/relaton_bib/contributor.rb', line 174 def contact @contact end |
#uri ⇒ URI (readonly)
171 172 173 |
# File 'lib/relaton_bib/contributor.rb', line 171 def uri @uri end |
Instance Method Details
#to_asciibib(prefix = "") ⇒ String
204 205 206 207 208 209 210 211 212 213 |
# File 'lib/relaton_bib/contributor.rb', line 204 def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity pref = prefix.empty? ? prefix : prefix + "." out = "" out += "#{pref}url:: #{uri}\n" if uri addr = contact.select { |c| c.is_a? RelatonBib::Address } addr.each { |ct| out += ct.to_asciibib prefix, addr.size } cont = contact.select { |c| c.is_a? RelatonBib::Contact } cont.each { |ct| out += ct.to_asciibib prefix, cont.size } out end |
#to_hash ⇒ Hash
195 196 197 198 199 200 |
# File 'lib/relaton_bib/contributor.rb', line 195 def to_hash hash = {} hash["url"] = uri.to_s if uri hash["contact"] = single_element_array(contact) if contact&.any? hash end |
#to_xml(builder) ⇒ Object
190 191 192 |
# File 'lib/relaton_bib/contributor.rb', line 190 def to_xml(builder) contact.each { |contact| contact.to_xml builder } end |
#url ⇒ String
Returns url.
185 186 187 |
# File 'lib/relaton_bib/contributor.rb', line 185 def url @uri.to_s end |