Class: RelatonBib::Organization
- Inherits:
-
Contributor
- Object
- Contributor
- RelatonBib::Organization
- Defined in:
- lib/relaton_bib/organization.rb
Overview
Organization.
Constant Summary
Constants included from RelatonBib
Instance Attribute Summary collapse
- #abbreviation ⇒ RelatonBib::LocalizedString, NilClass readonly
- #identifier ⇒ Array<RelatonBib::OrgIdentifier> readonly
- #name ⇒ Array<RelatonBib::LocalizedString> readonly
- #subdivision ⇒ RelatonBib::LocalizedString, NilClass readonly
Attributes inherited from Contributor
Instance Method Summary collapse
-
#initialize(**args) ⇒ Organization
constructor
A new instance of Organization.
- #to_asciibib(prefix = "", count = 1) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(builder) ⇒ Object
Methods inherited from Contributor
Methods included from RelatonBib
Constructor Details
#initialize(**args) ⇒ Organization
Returns a new instance of Organization.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/relaton_bib/organization.rb', line 70 def initialize(**args) # rubocop:disable Metrics/AbcSize raise ArgumentError, "missing keyword: name" unless args[:name] super(url: args[:url], contact: args.fetch(:contact, [])) @name = if args[:name].is_a?(Array) args[:name].map { |n| localized_string(n) } else [localized_string(args[:name])] end @abbreviation = localized_string args[:abbreviation] @subdivision = localized_string args[:subdivision] @identifier = args.fetch(:identifier, []) end |
Instance Attribute Details
#abbreviation ⇒ RelatonBib::LocalizedString, NilClass (readonly)
56 57 58 |
# File 'lib/relaton_bib/organization.rb', line 56 def abbreviation @abbreviation end |
#identifier ⇒ Array<RelatonBib::OrgIdentifier> (readonly)
62 63 64 |
# File 'lib/relaton_bib/organization.rb', line 62 def identifier @identifier end |
#name ⇒ Array<RelatonBib::LocalizedString> (readonly)
53 54 55 |
# File 'lib/relaton_bib/organization.rb', line 53 def name @name end |
#subdivision ⇒ RelatonBib::LocalizedString, NilClass (readonly)
59 60 61 |
# File 'lib/relaton_bib/organization.rb', line 59 def subdivision @subdivision end |
Instance Method Details
#to_asciibib(prefix = "", count = 1) ⇒ String
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/relaton_bib/organization.rb', line 112 def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity pref = prefix.sub /\*$/, "organization" out = count > 1 ? "#{pref}::\m" : "" name.each { |n| out += n.to_asciibib "#{pref}.name", name.size } out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation out += subdivision.to_asciibib "#{pref}.subdivision" if subdivision identifier.each { |n| out += n.to_asciibib pref, identifier.size } out += super pref out end |
#to_hash ⇒ Hash
101 102 103 104 105 106 107 |
# File 'lib/relaton_bib/organization.rb', line 101 def to_hash hash = { "name" => single_element_array(name) } hash["abbreviation"] = abbreviation.to_hash if abbreviation hash["identifier"] = single_element_array(identifier) if identifier&.any? hash["subdivision"] = subdivision.to_hash if subdivision { "organization" => hash.merge(super) } end |
#to_xml(builder) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/relaton_bib/organization.rb', line 87 def to_xml(builder) # rubocop:disable Metrics/AbcSize 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 identifier.each { |identifier| identifier.to_xml builder } super end end |