Sha256: 82519360adf4f95cd9d6dfadafe0d9003234fbf59b21a170746611192ec78fc0

Contents?: true

Size: 780 Bytes

Versions: 14

Compression:

Stored size: 780 Bytes

Contents

# frozen_string_literal: true

require 'arclight/exceptions'

module Arclight
  ##
  # A utility class to normalize titles, typically by joining
  # the title and date, e.g., "My Title, 1990-2000"
  class NormalizedTitle
    # @param [String] `title` from the `unittitle`
    # @param [String] `date` from the `unitdate`
    def initialize(title, date = nil)
      @title = title.gsub(/\s*,\s*$/, '').strip if title.present?
      @date = date.strip if date.present?
    end

    # @return [String] the normalized title/date
    def to_s
      normalize
    end

    private

    attr_reader :title, :date, :default

    def normalize
      result = [title, date].compact.join(', ')
      raise Arclight::Exceptions::TitleNotFound if result.blank?

      result
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
arclight-1.4.0 lib/arclight/normalized_title.rb
arclight-1.3.0 lib/arclight/normalized_title.rb
arclight-1.2.0 lib/arclight/normalized_title.rb
arclight-1.1.3 lib/arclight/normalized_title.rb
arclight-1.1.2 lib/arclight/normalized_title.rb
arclight-1.1.1 lib/arclight/normalized_title.rb
arclight-1.1.0 lib/arclight/normalized_title.rb
arclight-1.0.1 lib/arclight/normalized_title.rb
arclight-1.0.0 lib/arclight/normalized_title.rb
arclight-1.0.0.beta6 lib/arclight/normalized_title.rb
arclight-1.0.0.beta4 lib/arclight/normalized_title.rb
arclight-1.0.0.beta3 lib/arclight/normalized_title.rb
arclight-1.0.0.beta2 lib/arclight/normalized_title.rb
arclight-1.0.0.beta1 lib/arclight/normalized_title.rb