lib/datacite/mapping/date.rb in datacite-mapping-0.1.6 vs lib/datacite/mapping/date.rb in datacite-mapping-0.1.7
- old
+ new
@@ -52,22 +52,10 @@
# @!attribute [r] nsec
# @return [Integer, nil] The nanoseconds. Can be `nil` if no nanoseconds were specified.
class Date
include XML::Mapping
- # @!attribute [rw] type
- # @return [DateType] the type of date. Cannot be nil.
- typesafe_enum_node :type, '@dateType', class: DateType
- maybe_alias :_type=, :type=
- private :_type=
-
- # @!method value
- # @return [String] The value as a string. May be any [W3C DateTime format](http://www.w3.org/TR/NOTE-datetime).
- text_node :value, 'text()'
- maybe_alias :_value=, :value=
- private :_value=
-
attr_reader :year
attr_reader :month
attr_reader :day
attr_reader :hour
attr_reader :minute
@@ -84,11 +72,11 @@
self.value = value
end
def type=(val)
fail ArgumentError, 'Date type cannot be nil' unless val
- self._type = val
+ @type = val
end
# Sets the value.
#
# @param val [DateTime, Date, Integer, String] The value, as a `DateTime`, `Date`, or `Integer`,
@@ -105,11 +93,11 @@
@minute = @date_time.minute if @date_time
@sec = @date_time.sec if @date_time
@nsec = @date_time.to_time.nsec if @date_time
end
fail ArgumentError, "Unable to parse date value '#{val}'" unless @year
- self._value = new_value
+ @value = new_value
end
private
def to_year(val)
@@ -146,8 +134,15 @@
rescue ArgumentError => e
Mapping.log.debug("Can't extract Date from date value '#{val}': #{e}")
nil
end
+ # @!attribute [rw] type
+ # @return [DateType] the type of date. Cannot be nil.
+ typesafe_enum_node :type, '@dateType', class: DateType
+
+ # @!method value
+ # @return [String] The value as a string. May be any [W3C DateTime format](http://www.w3.org/TR/NOTE-datetime).
+ text_node :value, 'text()'
end
end
end