class RelatonBipm::Committee
Attributes
acronym[R]
@return [String]
content[R]
@return [RelatonBib::LocalizedString]
Public Class Methods
new(acronym:, content: nil)
click to toggle source
@param acronym [String] @param content [RelatonBib::LocalisedString, String, nil]
# File lib/relaton_bipm/committee.rb, line 11 def initialize(acronym:, content: nil) acronyms = YAML.load_file File.join(__dir__, "acronyms.yaml") unless acronyms[acronym] warn "[relaton-bipm] WARNING: invalid acronym: #{acronym}. Allowed "\ "values: #{acronyms.map { |k, _v| k }.join ', '}" end @acronym = acronym @content = localized_content content, acronyms[acronym] end
Public Instance Methods
to_asciibib(prefix, count = 1)
click to toggle source
@param prefix [String] @param count [Integer] @return [String]
# File lib/relaton_bipm/committee.rb, line 30 def to_asciibib(prefix, count = 1) pref = prefix.empty? ? prefix : "#{prefix}." pref += "committee" out = count > 1 ? "#{pref}::\n" : "" out += "#{pref}.acronym:: #{acronym}\n" out + content.to_asciibib(pref) end
to_hash()
click to toggle source
@return [Hash]
# File lib/relaton_bipm/committee.rb, line 39 def to_hash hash = { "acronym" => acronym } cnt = content.to_hash case cnt when Array then hash["variants"] = cnt when Hash then hash.merge! cnt else hash["content"] = cnt end hash end
to_xml(builder)
click to toggle source
@param builder [Nokogiri::XML::Builder]
# File lib/relaton_bipm/committee.rb, line 23 def to_xml(builder) builder.committee(acronym: acronym) { |b| content.to_xml b } end
Private Instance Methods
localized_content(cnt, acr)
click to toggle source
# File lib/relaton_bipm/committee.rb, line 52 def localized_content(cnt, acr) if cnt.is_a? String RelatonBib::LocalizedString.new cnt elsif (cnt.nil? || cnt.empty?) && acr && acr["en"] RelatonBib::LocalizedString.new(acr["en"], "en", "Latn") else cnt end end