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.



277
278
279
280
# File 'lib/stanford-mods/imprint.rb', line 277

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

Instance Attribute Details

#startObject (readonly)

Returns the value of attribute start.



275
276
277
# File 'lib/stanford-mods/imprint.rb', line 275

def start
  @start
end

#stopObject (readonly)

Returns the value of attribute stop.



275
276
277
# File 'lib/stanford-mods/imprint.rb', line 275

def stop
  @stop
end

Instance Method Details

#base_valueObject

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



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

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

#base_valuesObject

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



292
293
294
# File 'lib/stanford-mods/imprint.rb', line 292

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

#decoded_value(**kwargs) ⇒ Object



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

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.



297
298
299
# File 'lib/stanford-mods/imprint.rb', line 297

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

#key_date?Boolean

If either date in the range is a key date

Returns:

  • (Boolean)


307
308
309
# File 'lib/stanford-mods/imprint.rb', line 307

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

#parsed_date?Boolean

If either date in the range was successfully parsed

Returns:

  • (Boolean)


312
313
314
# File 'lib/stanford-mods/imprint.rb', line 312

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)


302
303
304
# File 'lib/stanford-mods/imprint.rb', line 302

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.



325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/stanford-mods/imprint.rb', line 325

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



282
283
284
# File 'lib/stanford-mods/imprint.rb', line 282

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