Sha256: 0c4aee3495006215f2a69692c4a39ae5e6fd60ff77186c6d72f3874419e3a654
Contents?: true
Size: 1.63 KB
Versions: 6
Compression:
Stored size: 1.63 KB
Contents
module RelatonBipm class Committee # @return [String] attr_reader :acronym # @return [RelatonBib::LocalizedString] attr_reader :content # @param acronym [String] # @param content [RelatonBib::LocalisedString, String, nil] 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 # @param builder [Nokogiri::XML::Builder] def to_xml(builder) builder.committee(acronym: acronym) { |b| content.to_xml b } end # @param prefix [String] # @param count [Integer] # @return [String] 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 # @return [Hash] def to_hash hash = { "acronym" => acronym } cnt = content.to_hash if cnt.is_a? Array then hash["variants"] = cnt elsif cnt.is_a? Hash then hash.merge! cnt else hash["content"] = cnt end hash end private 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 end end
Version data entries
6 entries across 6 versions & 1 rubygems