Sha256: aa14a9b6a2f648b6a5bcbd7b4c1544c881de516240510a2a0cae793067d9cb1a
Contents?: true
Size: 1.36 KB
Versions: 5
Compression:
Stored size: 1.36 KB
Contents
# frozen_string_literal: true module Arclight ## # A utility class to normalize dates, typically by joining inclusive and bulk dates # e.g., "1990-2000, bulk 1990-1999" # @see http://www2.archivists.org/standards/DACS/part_I/chapter_2/4_date class NormalizedDate # @param [String | Array<String>] `inclusive` from the `unitdate` # @param [String] `bulk` from the `unitdate` # @param [String] `other` from the `unitdate` when type is not specified 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 # @return [String] the normalized title/date def to_s normalize end private attr_reader :inclusive, :bulk, :other # @see http://www2.archivists.org/standards/DACS/part_I/chapter_2/4_date for rules def normalize if inclusive.present? result = inclusive.to_s result << ", bulk #{bulk}" if bulk.present? elsif other.present? result = other.to_s else result = nil end return if result.blank? result.strip end end end
Version data entries
5 entries across 5 versions & 1 rubygems