Class: RelatonBib::Organization

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

Overview

Organization.

Constant Summary

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Attributes inherited from Contributor

#contact, #uri

Instance Method Summary collapse

Methods inherited from Contributor

#url

Methods included from RelatonBib

array, format_date, grammar_hash, parse_date, parse_yaml

Methods included from Config

#configuration, #configure

Constructor Details

#initialize(**args) ⇒ Organization

Returns a new instance of Organization.

Parameters:

Raises:

  • (ArgumentError)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/relaton_bib/organization.rb', line 74

def initialize(**args) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  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  = (args[:subdivision] || []).map do |sd|
    localized_string sd
  end
  @identifier = args.fetch(:identifier, [])
  @logo = args[:logo]
end

Instance Attribute Details

#abbreviationRelatonBib::LocalizedString? (readonly)

Returns:



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

def abbreviation
  @abbreviation
end

#identifierArray<RelatonBib::OrgIdentifier> (readonly)



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

def identifier
  @identifier
end

#logoRelatonBib::Image? (readonly)

Returns:



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

def 
  @logo
end

#nameArray<RelatonBib::LocalizedString> (readonly)



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

def name
  @name
end

#subdivisionArray<RelatonBib::LocalizedString> (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

Parameters:

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

Returns:

  • (String)


127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/relaton_bib/organization.rb', line 127

def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  pref = prefix.sub(/\*$/, "organization")
  out = count > 1 ? "#{pref}::\n" : ""
  name.each { |n| out += n.to_asciibib "#{pref}.name", name.size }
  out += abbreviation.to_asciibib "#{pref}.abbreviation" if abbreviation
  subdivision.each do |sd|
    out += "#{pref}.subdivision::" if subdivision.size > 1
    out += sd.to_asciibib "#{pref}.subdivision"
  end
  identifier.each { |n| out += n.to_asciibib pref, identifier.size }
  out += super pref
  out += .to_asciibib "#{pref}.logo" if 
  out
end

#to_hashHash

Returns:

  • (Hash)


113
114
115
116
117
118
119
120
121
122
# File 'lib/relaton_bib/organization.rb', line 113

def to_hash # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
  hash = { "name" => single_element_array(name) }
  hash["abbreviation"] = abbreviation.to_hash if abbreviation
  hash["identifier"] = single_element_array(identifier) if identifier&.any?
  if subdivision&.any?
    hash["subdivision"] = single_element_array(subdivision)
  end
  hash["logo"] = .to_hash if 
  { "organization" => hash.merge(super) }
end

#to_xml(**opts) ⇒ Object

Parameters:

  • opts (Hash)

Options Hash (**opts):

  • :builder (Nokogiri::XML::Builder)

    XML builder

  • :lang (String)

    language



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/relaton_bib/organization.rb', line 96

def to_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
  opts[:builder].organization do |builder|
    nm = name.select { |n| n.language&.include? opts[:lang] }
    nm = name unless nm.any?
    nm.each { |n| builder.name { |b| n.to_xml b } }
    sbdv = subdivision.select { |sd| sd.language&.include? opts[:lang] }
    sbdv = subdivision unless sbdv.any?
    sbdv.each { |sd| builder.subdivision { sd.to_xml builder } }
    builder.abbreviation { |a| abbreviation.to_xml a } if abbreviation
    builder.uri url if uri
    identifier.each { |identifier| identifier.to_xml builder }
    super builder
    builder. { |b| .to_xml b } if 
  end
end