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.
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
#start ⇒ Object (readonly)
Returns the value of attribute start.
275 276 277 |
# File 'lib/stanford-mods/imprint.rb', line 275 def start @start end |
#stop ⇒ Object (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_value ⇒ Object
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_values ⇒ Object
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 |
#encoding ⇒ Object
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
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
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
302 303 304 |
# File 'lib/stanford-mods/imprint.rb', line 302 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.
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_key ⇒ Object
282 283 284 |
# File 'lib/stanford-mods/imprint.rb', line 282 def sort_key @start&.sort_key || @stop&.sort_key end |