Class: Arclight::NormalizedDate

Inherits:
Object
  • Object
show all
Defined in:
lib/arclight/normalized_date.rb

Overview

A utility class to normalize dates, typically by joining inclusive and bulk dates e.g., “1990-2000, bulk 1990-1999”

Instance Method Summary collapse

Constructor Details

#initialize(inclusive, bulk = [], other = []) ⇒ NormalizedDate

Returns a new instance of NormalizedDate.

Parameters:

  • `inclusive` (String | Array<String>)

    from the ‘unitdate`

  • `bulk` (Array<String>)

    from the ‘unitdate`

  • `other` (Array<String>)

    from the ‘unitdate` when type is not specified



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/arclight/normalized_date.rb', line 12

def initialize(inclusive, bulk = [], other = [])
  @inclusive = (inclusive || []).map do |inclusive_text|
    if inclusive_text.is_a? Array # of YYYY-YYYY for ranges
      # NOTE: This code is not routable AFAICT in actual indexing.
      # We pass arrays of strings (or xml nodes) here, and never a multidimensional array
      year_range(inclusive_text)
    elsif inclusive_text.present?
      inclusive_text.strip
    end
  end&.join(', ')

  @bulk = Array.wrap(bulk).compact.map(&:strip).join(', ')
  @other = Array.wrap(other).compact.map(&:strip).join(', ')
end

Instance Method Details

#to_sString

Returns the normalized title/date.

Returns:

  • (String)

    the normalized title/date



28
29
30
# File 'lib/arclight/normalized_date.rb', line 28

def to_s
  normalize
end