Class: RelatonBib::Validity

Inherits:
Object show all
Defined in:
lib/relaton_bib/validity.rb

Constant Summary collapse

FORMAT =
"%Y-%m-%d %H:%M".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(begins: nil, ends: nil, revision: nil) ⇒ Validity

Returns a new instance of Validity.

Parameters:

  • begins (Time, nil) (defaults to: nil)
  • ends (Time, nil) (defaults to: nil)
  • revision (Time, nil) (defaults to: nil)


17
18
19
20
21
# File 'lib/relaton_bib/validity.rb', line 17

def initialize(begins: nil, ends: nil, revision: nil)
  @begins   = begins
  @ends     = ends
  @revision = revision
end

Instance Attribute Details

#beginsTime? (readonly)

Returns:

  • (Time, nil)


6
7
8
# File 'lib/relaton_bib/validity.rb', line 6

def begins
  @begins
end

#endsTime? (readonly)

Returns:

  • (Time, nil)


9
10
11
# File 'lib/relaton_bib/validity.rb', line 9

def ends
  @ends
end

#revisionTime? (readonly)

Returns:

  • (Time, nil)


12
13
14
# File 'lib/relaton_bib/validity.rb', line 12

def revision
  @revision
end

Instance Method Details

#to_asciibib(prefix = "") ⇒ String

Parameters:

  • prefix (String) (defaults to: "")

Returns:

  • (String)


43
44
45
46
47
48
49
50
# File 'lib/relaton_bib/validity.rb', line 43

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

#to_hashHash

Returns:

  • (Hash)


33
34
35
36
37
38
39
# File 'lib/relaton_bib/validity.rb', line 33

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

#to_xml(builder) ⇒ Object

Parameters:

  • (Nokogiri::XML::Builder)


24
25
26
27
28
29
30
# File 'lib/relaton_bib/validity.rb', line 24

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