lib/datacite/mapping/date.rb in datacite-mapping-0.2.5 vs lib/datacite/mapping/date.rb in datacite-mapping-0.3.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'xml/mapping_extensions' require 'datacite/mapping/date_value' module Datacite @@ -65,11 +67,11 @@ self.type = type self.value = value end def type=(val) - fail ArgumentError, 'Date type cannot be nil' unless val + raise ArgumentError, 'Date type cannot be nil' unless val @type = val end def value=(val) # rubocop:disable Metrics/AbcSize parts = val.to_s.split('/', -1) # negative limit so we don't drop trailing empty string @@ -78,18 +80,18 @@ @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 - fail ArgumentError, "Unable to parse date value #{val}" + raise ArgumentError, "Unable to parse date value #{val}" end @value = date_value ? date_value.to_s : "#{range_start}/#{range_end}" end def <=>(other) return nil unless other.class == self.class - [:date_value, :range_start, :range_end, :type].each do |v| + %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 @@ -99,11 +101,9 @@ end def to_s @value end - - private # @!attribute [rw] type # @return [DateType] the type of date. Cannot be nil. typesafe_enum_node :type, '@dateType', class: DateType