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 = nil, other = nil) ⇒ NormalizedDate

Returns a new instance of NormalizedDate.

Parameters:

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

    from the ‘unitdate`

  • `bulk` (String)

    from the ‘unitdate`

  • `other` (String)

    from the ‘unitdate` when type is not specified



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

def initialize(inclusive, bulk = nil, other = nil)
  if inclusive.is_a? Array # of YYYY-YYYY for ranges
    @inclusive = YearRange.new(inclusive.include?('/') ? inclusive : inclusive.map { |v| v.tr('-', '/') }).to_s
  elsif inclusive.present?
    @inclusive = inclusive.strip
  end
  @bulk = bulk.strip if bulk.present?
  @other = other.strip if other.present?
end

Instance Method Details

#to_sString

Returns the normalized title/date.

Returns:

  • (String)

    the normalized title/date



23
24
25
# File 'lib/arclight/normalized_date.rb', line 23

def to_s
  normalize
end