Sha256: a7ea7ec7880b5fd16d5aa32ec371735329be966af098033634e7bff4d132f33a

Contents?: true

Size: 1.02 KB

Versions: 8

Compression:

Stored size: 1.02 KB

Contents

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

    # @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.validityRevision 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
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
relaton-bib-0.3.12 lib/relaton_bib/validity.rb
relaton-bib-0.3.11 lib/relaton_bib/validity.rb
relaton-bib-0.3.10 lib/relaton_bib/validity.rb
relaton-bib-0.3.9 lib/relaton_bib/validity.rb
relaton-bib-0.3.8 lib/relaton_bib/validity.rb
relaton-bib-0.3.7 lib/relaton_bib/validity.rb
relaton-bib-0.3.6 lib/relaton_bib/validity.rb
relaton-bib-0.3.5 lib/relaton_bib/validity.rb