Sha256: 4520cd43c52e7b44ca8b68a8e8ef1443be840789a5f80cd1703bf82f8902ccb0
Contents?: true
Size: 1.97 KB
Versions: 77
Compression:
Stored size: 1.97 KB
Contents
module RelatonBib class BiblioNoteCollection extend Forwardable def_delegators :@array, :[], :first, :last, :empty?, :any?, :size, :each, :map, :reduce, :detect, :length def initialize(notes) @array = notes end # @param bibnote [RelatonBib::BiblioNote] # @return [self] def <<(bibnote) @array << bibnote self end # @param opts [Hash] # @option opts [Nokogiri::XML::Builder] XML builder # @option opts [String] :lang language def to_xml(**opts) bnc = @array.select { |bn| bn.language&.include? opts[:lang] } bnc = @array unless bnc.any? bnc.each { |bn| bn.to_xml opts[:builder] } end end class BiblioNote < FormattedString # @return [String, NilClass] attr_reader :type # @param content [String] # @param type [String, NilClass] # @param language [String, NilClass] language code Iso639 # @param script [String, NilClass] script code Iso15924 # @param format [String, NilClass] the content format def initialize(content:, type: nil, language: nil, script: nil, format: nil) @type = type super content: content, language: language, script: script, format: format end # @param builder [Nokogiri::XML::Builder] def to_xml(builder) xml = builder.note { super } xml[:type] = type if type xml end # @return [Hash] def to_hash hash = super return hash unless type hash = { "content" => hash } if hash.is_a? String hash["type"] = type hash end # @param prefix [String] # @param count [Integer] number of notes # @return [String] def to_asciibib(prefix = "", count = 1) pref = prefix.empty? ? prefix : prefix + "." has_attrs = !(type.nil? || type.empty?) out = count > 1 && has_attrs ? "#{pref}biblionote::\n" : "" out += "#{pref}biblionote.type:: #{type}\n" if type out += super "#{pref}biblionote", 1, has_attrs out end end end
Version data entries
77 entries across 77 versions & 1 rubygems