Class: IsoBibItem::Organization

Inherits:
Contributor show all
Defined in:
lib/iso_bib_item/organization.rb

Overview

Organization.

Instance Attribute Summary collapse

Attributes inherited from Contributor

#contacts, #uri

Instance Method Summary collapse

Methods inherited from Contributor

#url

Constructor Details

#initialize(name:, abbreviation: nil, url: nil, identifiers: []) ⇒ Organization

Returns a new instance of Organization.

Parameters:

  • name (String)
  • abbreviation (String) (defaults to: nil)
  • url (String) (defaults to: nil)


50
51
52
53
54
55
# File 'lib/iso_bib_item/organization.rb', line 50

def initialize(name:, abbreviation: nil, url: nil, identifiers: [])
  super(url: url)
  @name = name.is_a?(Array) ? name.map { |n| hash2locstr(n) } : [hash2locstr(name)]
  @abbreviation = LocalizedString.new abbreviation
  @identifiers  = identifiers
end

Instance Attribute Details

#abbreviationIsoBibItem::LocalizedString (readonly)



37
38
39
# File 'lib/iso_bib_item/organization.rb', line 37

def abbreviation
  @abbreviation
end

#identifiersArray<IsoBibItem::OrgIdentifier> (readonly)



40
41
42
# File 'lib/iso_bib_item/organization.rb', line 40

def identifiers
  @identifiers
end

#nameIsoBibItem::LocalizedString (readonly)



34
35
36
# File 'lib/iso_bib_item/organization.rb', line 34

def name
  @name
end

Instance Method Details

#hash2locstr(name) ⇒ Object



42
43
44
# File 'lib/iso_bib_item/organization.rb', line 42

def hash2locstr(name)
  name.is_a?(Hash) ? LocalizedString.new(name[:content], name[:language], name[:script]) : LocalizedString.new(name)
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/iso_bib_item/organization.rb', line 58

def to_xml(builder)
  builder.organization do
    name.each do |n|
      builder.name { |b| n.to_xml b }
    end
    builder.abbreviation { |a| abbreviation.to_xml a } if abbreviation&.to_s
    builder.uri uri.to_s if uri
    identifiers.each { |identifier| identifier.to_xml builder }
    super
  end
end