Class: Stanford::Mods::Imprint::DateRange

Inherits:
Object
  • Object
show all
Defined in:
lib/stanford-mods/imprint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start: nil, stop: nil) ⇒ DateRange

Returns a new instance of DateRange.



289
290
291
292
# File 'lib/stanford-mods/imprint.rb', line 289

def initialize(start: nil, stop: nil)
  @start = start
  @stop = stop
end

Instance Attribute Details

#startObject (readonly)

Returns the value of attribute start.



287
288
289
# File 'lib/stanford-mods/imprint.rb', line 287

def start
  @start
end

#stopObject (readonly)

Returns the value of attribute stop.



287
288
289
# File 'lib/stanford-mods/imprint.rb', line 287

def stop
  @stop
end

Instance Method Details

#base_valueObject

Base value as hyphen-joined string. Used for comparison/deduping.



299
300
301
# File 'lib/stanford-mods/imprint.rb', line 299

def base_value
  "#{@start&.base_value}-#{@stop&.base_value}"
end

#base_valuesObject

Base values as array. Used for comparison/deduping of individual dates.



304
305
306
# File 'lib/stanford-mods/imprint.rb', line 304

def base_values
  [@start&.base_value, @stop&.base_value].compact
end

#decoded_value(**kwargs) ⇒ Object



328
329
330
331
332
333
# File 'lib/stanford-mods/imprint.rb', line 328

def decoded_value(**kwargs)
  [
    @start&.decoded_value(**kwargs),
    @stop&.decoded_value(**kwargs)
  ].uniq.join(' - ')
end

#encodingObject

The encoding value for the start of the range, or stop if not present.



309
310
311
# File 'lib/stanford-mods/imprint.rb', line 309

def encoding
  @start&.encoding || @stop&.encoding
end

#key_date?Boolean

If either date in the range is a key date

Returns:

  • (Boolean)


319
320
321
# File 'lib/stanford-mods/imprint.rb', line 319

def key_date?
  @start&.key_date? || @stop&.key_date?
end

#parsed_date?Boolean

If either date in the range was successfully parsed

Returns:

  • (Boolean)


324
325
326
# File 'lib/stanford-mods/imprint.rb', line 324

def parsed_date?
  @start&.parsed_date? || @stop&.parsed_date?
end

#qualified?Boolean

If either date in the range is qualified in any way

Returns:

  • (Boolean)


314
315
316
# File 'lib/stanford-mods/imprint.rb', line 314

def qualified?
  @start&.qualified? || @stop&.qualified?
end

#qualified_valueObject

Decoded dates with “BCE” or “CE” and qualifier markers applied to the entire range, or individually if dates differ.



337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/stanford-mods/imprint.rb', line 337

def qualified_value
  if @start&.qualifier == @stop&.qualifier
    qualifier = @start&.qualifier || @stop&.qualifier
    date = decoded_value
    return "[ca. #{date}]" if qualifier == 'approximate'
    return "[#{date}?]" if qualifier == 'questionable'
    return "[#{date}]" if qualifier == 'inferred'

    date
  else
    "#{@start&.qualified_value} - #{@stop&.qualified_value}"
  end
end

#sort_keyObject



294
295
296
# File 'lib/stanford-mods/imprint.rb', line 294

def sort_key
  @start&.sort_key || @stop&.sort_key
end