class Datacite::Mapping::Date
Represents a DataCite `<date/>` field, which can be a year, date (year-month-day or just year-month), ISO8601 datetime, or [RKMS-ISO8601](www.ukoln.ac.uk/metadata/dcmi/collection-RKMS-ISO8601/) date range.
@!attribute [r] date_value
@return [DateValue, nil] the single date/time represented by this `<date/>` field, if it does not represent a ragne
@!attribute [r] range_start
@return [DateValue, nil] the start of the date range represented by this `<date/> field`, if it represents a range, and the range is not open on the lower end
@!attribute [r] range_end
@return [DateValue, nil] the end of the date range represented by this `<date/> field`, if it represents a range, and the range is not open on the upper end
Attributes
date_value[R]
range_end[R]
range_start[R]
Public Class Methods
new(type:, value:)
click to toggle source
Initializes a new `Date`
@param type [DateType] the type of date. Cannot be nil. @param value [DateTime, Date
, Integer, String] The value, as a `DateTime`, `Date`, or `Integer`,
or as a `String` in any [W3C DateTime format](http://www.w3.org/TR/NOTE-datetime)
# File lib/datacite/mapping/date.rb, line 72 def initialize(type:, value:) self.type = type self.value = value end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/datacite/mapping/date.rb, line 97 def <=>(other) return nil unless other.class == self.class %i[date_value range_start range_end type].each do |v| order = send(v) <=> other.send(v) return order if order.nonzero? end 0 end
hash()
click to toggle source
# File lib/datacite/mapping/date.rb, line 107 def hash [date_value, range_start, range_end, type].hash end
to_s()
click to toggle source
# File lib/datacite/mapping/date.rb, line 111 def to_s @value end
type=(val)
click to toggle source
# File lib/datacite/mapping/date.rb, line 77 def type=(val) raise ArgumentError, 'Date type cannot be nil' unless val @type = val end
value=(val)
click to toggle source
# File lib/datacite/mapping/date.rb, line 83 def value=(val) # rubocop:disable Metrics/AbcSize parts = val.to_s.split('/', -1) # negative limit so we don't drop trailing empty string @date_value, @range_start, @range_end = nil if parts.size == 1 @date_value = DateValue.new(val) elsif parts.size == 2 @range_start, @range_end = parts.map(&:strip).map { |part| DateValue.new(part) unless part == '' } # puts "#{val} -> [#{range_start}, #{range_end}]" else raise ArgumentError, "Unable to parse date value #{val}" end @value = date_value ? date_value.to_s : "#{range_start}/#{range_end}" end