Class: RelatonBib::Organization

Inherits:
Contributor show all
Defined in:
lib/relaton_bib/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(**args) ⇒ Organization

Returns a new instance of Organization.

Parameters:

  • name (String, Hash, Array<String, Hash>)
  • abbreviation (RelatoBib::LocalizedStrig, String)
  • subdivision (RelatoBib::LocalizedStrig, String)
  • url (String)
  • identifiers (Array<RelatonBib::OrgIdentifier>)
  • contacts (Array<RelatonBib::Address, RelatonBib::Phone>)

Raises:

  • (ArgumentError)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/relaton_bib/organization.rb', line 75

def initialize(**args)
  raise ArgumentError, "missing keyword: name" unless args[:name]

  super(url: args[:url], contacts: args.fetch(:contacts, []))

  @name = if args[:name].is_a?(Array)
            args[:name].map { |n| hash2locstr(n) }
          else
            [hash2locstr(args[:name])]
          end

  @abbreviation = if args[:abbreviation].is_a?(String)
                    LocalizedString.new(args[:abbreviation])
                  else
                    args[:abbreviation]
                  end

  @subdivision  = if args[:subdivision].is_a?(String)
                    LocalizedString.new(args[:subdivision])
                  else
                    args[:subdivision]
                  end

  @identifiers  = args.fetch(:identifiers, [])
end

Instance Attribute Details

#abbreviationRelatonBib::LocalizedString (readonly)



55
56
57
# File 'lib/relaton_bib/organization.rb', line 55

def abbreviation
  @abbreviation
end

#identifiersArray<RelatonBib::OrgIdentifier> (readonly)

Returns:



61
62
63
# File 'lib/relaton_bib/organization.rb', line 61

def identifiers
  @identifiers
end

#nameArray<RelatonBib::LocalizedString> (readonly)

Returns:



52
53
54
# File 'lib/relaton_bib/organization.rb', line 52

def name
  @name
end

#subdivisionRelatonBib::LocalizedString (readonly)



58
59
60
# File 'lib/relaton_bib/organization.rb', line 58

def subdivision
  @subdivision
end

Instance Method Details

#hash2locstr(name) ⇒ Object



63
64
65
66
67
# File 'lib/relaton_bib/organization.rb', line 63

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)


102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/relaton_bib/organization.rb', line 102

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