Class: RelatonBib::Organization
Overview
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, formattedref, hash_to_bib, localizedstring, localname, parse_date, symbolize, timestamp_hash
Constructor Details
Returns a new instance of Organization.
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/relaton_bib/organization.rb', line 64
def initialize(**args)
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
50
51
52
|
# File 'lib/relaton_bib/organization.rb', line 50
def abbreviation
@abbreviation
end
|
56
57
58
|
# File 'lib/relaton_bib/organization.rb', line 56
def identifier
@identifier
end
|
47
48
49
|
# File 'lib/relaton_bib/organization.rb', line 47
def name
@name
end
|
53
54
55
|
# File 'lib/relaton_bib/organization.rb', line 53
def subdivision
@subdivision
end
|
Instance Method Details
#to_hash ⇒ Hash
95
96
97
98
99
100
101
|
# File 'lib/relaton_bib/organization.rb', line 95
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
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/relaton_bib/organization.rb', line 81
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
identifier.each { |identifier| identifier.to_xml builder }
super
end
end
|