Class: Stanford::Mods::Imprint::DateRange
- Inherits:
-
Object
- Object
- Stanford::Mods::Imprint::DateRange
- Defined in:
- lib/stanford-mods/imprint.rb
Instance Attribute Summary collapse
-
#start ⇒ Object
readonly
Returns the value of attribute start.
-
#stop ⇒ Object
readonly
Returns the value of attribute stop.
Instance Method Summary collapse
-
#base_value ⇒ Object
Base value as hyphen-joined string.
-
#base_values ⇒ Object
Base values as array.
- #decoded_value(**kwargs) ⇒ Object
-
#encoding ⇒ Object
The encoding value for the start of the range, or stop if not present.
-
#initialize(start: nil, stop: nil) ⇒ DateRange
constructor
A new instance of DateRange.
-
#key_date? ⇒ Boolean
If either date in the range is a key date.
-
#parsed_date? ⇒ Boolean
If either date in the range was successfully parsed.
-
#qualified? ⇒ Boolean
If either date in the range is qualified in any way.
-
#qualified_value ⇒ Object
Decoded dates with “BCE” or “CE” and qualifier markers applied to the entire range, or individually if dates differ.
- #sort_key ⇒ Object
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
#start ⇒ Object (readonly)
Returns the value of attribute start.
287 288 289 |
# File 'lib/stanford-mods/imprint.rb', line 287 def start @start end |
#stop ⇒ Object (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_value ⇒ Object
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_values ⇒ Object
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 |
#encoding ⇒ Object
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
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
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
314 315 316 |
# File 'lib/stanford-mods/imprint.rb', line 314 def qualified? @start&.qualified? || @stop&.qualified? end |
#qualified_value ⇒ Object
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_key ⇒ Object
294 295 296 |
# File 'lib/stanford-mods/imprint.rb', line 294 def sort_key @start&.sort_key || @stop&.sort_key end |