Class: RelatonBib::BibliographicDate

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

Overview

Bibliographic date.

Constant Summary collapse

TYPES =
%w[published accessed created implemented obsoleted confirmed
           updated issued transmitted copied unchanged circulated
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, on: nil, from: nil, to: nil) ⇒ BibliographicDate

Returns a new instance of BibliographicDate.

Parameters:

  • type (String)

    “published”, “accessed”, “created”, “activated”

  • from (String) (defaults to: nil)
  • to (String) (defaults to: nil)

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
51
# File 'lib/relaton_bib/bibliographic_date.rb', line 41

def initialize(type:, on: nil, from: nil, to: nil)
  raise ArgumentError, "expected :on or :from argument" unless on || from

  TYPES.include?(type) or
    raise ArgumentError, %{Type "#{type}" is invalid.} unless

  @type = type
  @on   = parse_date on
  @from = parse_date from
  @to   = parse_date to
end

Instance Attribute Details

#fromTime (readonly)

Returns:

  • (Time)


30
31
32
# File 'lib/relaton_bib/bibliographic_date.rb', line 30

def from
  @from
end

#onTime (readonly)

Returns:

  • (Time)


36
37
38
# File 'lib/relaton_bib/bibliographic_date.rb', line 36

def on
  @on
end

#toTime (readonly)

Returns:

  • (Time)


33
34
35
# File 'lib/relaton_bib/bibliographic_date.rb', line 33

def to
  @to
end

#typeString (readonly)

Returns:

  • (String)


27
28
29
# File 'lib/relaton_bib/bibliographic_date.rb', line 27

def type
  @type
end

Instance Method Details

#to_xml(builder, **opts) ⇒ Nokogiri::XML::Builder

Parameters:

  • builder (Nokogiri::XML::Builder)

Returns:

  • (Nokogiri::XML::Builder)


57
58
59
60
61
62
63
64
65
66
# File 'lib/relaton_bib/bibliographic_date.rb', line 57

def to_xml(builder, **opts)
  builder.date(type: type) do
    if on
      builder.on(opts[:no_year] ? "--" : date_format(on, opts[:date_format]))
    elsif from
      builder.from(opts[:no_year] ? "--" : date_format(from, opts[:date_format]))
      builder.to date_format(to, opts[:date_format]) if to
    end
  end
end