Sha256: 8266e45170de104fb94b8dd98822e1967a18006b206d124bf201def44a235c6a
Contents?: true
Size: 1.13 KB
Versions: 5
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true require 'time' module IsoBibItem # Bibliographic date. class BibliographicDate # @return [String] attr_reader :type # @return [Time] attr_reader :from # @return [Time] attr_reader :to # @return [Time] attr_reader :on # @param type [String] "published", "accessed", "created", "activated" # @param from [String] # @param to [String] def initialize(type:, on: nil, from: nil, to: nil) raise ArgumentError, 'expected :on or :form argument' unless on || from @type = type @on = Time.strptime(on, '%Y-%d') if on @from = Time.strptime(from, '%Y-%d') if from @to = Time.strptime(to, '%Y-%d') if to end # rubocop:disable Metric/AbcSize # @param builder [Nokogiri::XML::Builder] # @return [Nokogiri::XML::Builder] def to_xml(builder, **opts) builder.date(type: type) do if on builder.on(opts[:no_year] ? '--' : on.year) else builder.from(opts[:no_year] ? '--' : from.year) builder.to to.year if to end end end # rubocop:enable Metric/AbcSize end end
Version data entries
5 entries across 5 versions & 1 rubygems