Sha256: da8bd356e4bffd9940448227806d0fd19e664486f820bbcd5763e4c71cc572a6

Contents?: true

Size: 1.4 KB

Versions: 42

Compression:

Stored size: 1.4 KB

Contents

module RelatonBib
  class Validity
    FORMAT = "%Y-%m-%d %H:%M".freeze

    # @return [Time, NilClass]
    attr_reader :begins

    # @return [Time, NilClass]
    attr_reader :ends

    # @return [Time, NilClass]
    attr_reader :revision

    # @param begins [Time, NilClass]
    # @param ends [Time, NilClass]
    # @param revision [Time, NilClass]
    def initialize(begins: nil, ends: nil, revision: nil)
      @begins   = begins
      @ends     = ends
      @revision = revision
    end

    # @param [Nokogiri::XML::Builder]
    def to_xml(builder)
      builder.validity do
        builder.validityBegins begins.strftime(FORMAT) if begins
        builder.validityEnds ends.strftime(FORMAT) if ends
        builder.revision revision.strftime(FORMAT) if revision
      end
    end

    # @return [Hash]
    def to_hash
      hash = {}
      hash["begins"] = begins.strftime(FORMAT) if begins
      hash["ends"] = ends.strftime(FORMAT) if ends
      hash["revision"] = revision.strftime(FORMAT) if revision
      hash
    end

    # @param prefix [String]
    # @return [String]
    def to_asciibib(prefix = "")
      pref = prefix.empty? ? "validity." : "#{prefix}.validity."
      out = ""
      out += "#{pref}begins:: #{begins.strftime(FORMAT)}\n" if begins
      out += "#{pref}ends:: #{ends.strftime(FORMAT)}\n" if ends
      out += "#{pref}revision:: #{revision.strftime(FORMAT)}\n" if revision
      out
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
relaton-bib-1.14.2 lib/relaton_bib/validity.rb
relaton-bib-1.14.1 lib/relaton_bib/validity.rb
relaton-bib-1.14.0 lib/relaton_bib/validity.rb
relaton-bib-1.13.15 lib/relaton_bib/validity.rb
relaton-bib-1.13.14 lib/relaton_bib/validity.rb
relaton-bib-1.13.13 lib/relaton_bib/validity.rb
relaton-bib-1.13.12 lib/relaton_bib/validity.rb
relaton-bib-1.13.11 lib/relaton_bib/validity.rb
relaton-bib-1.13.10 lib/relaton_bib/validity.rb
relaton-bib-1.13.9 lib/relaton_bib/validity.rb
relaton-bib-1.13.8 lib/relaton_bib/validity.rb
relaton-bib-1.13.7 lib/relaton_bib/validity.rb
relaton-bib-1.13.6 lib/relaton_bib/validity.rb
relaton-bib-1.13.5 lib/relaton_bib/validity.rb
relaton-bib-1.13.4 lib/relaton_bib/validity.rb
relaton-bib-1.13.3 lib/relaton_bib/validity.rb
relaton-bib-1.13.2 lib/relaton_bib/validity.rb
relaton-bib-1.13.1 lib/relaton_bib/validity.rb
relaton-bib-1.13.0 lib/relaton_bib/validity.rb
relaton-bib-1.12.7 lib/relaton_bib/validity.rb