lib/project/coercer/string.rb in motion_coercible-0.2.0 vs lib/project/coercer/string.rb in motion_coercible-0.2.0.1
- old
+ new
@@ -1,5 +1,8 @@
+motion_require 'object'
+motion_require 'configurable'
+
module Coercible
class Coercer
# Coerce String values
class String < Object
@@ -92,9 +95,37 @@
# @return [Time]
#
# @api public
def to_time(value)
parse_value(::Time, value, __method__)
+ end
+
+ # Coerce given value to Date
+ #
+ # @example
+ # coercer[String].to_date(string) # => Date object
+ #
+ # @param [String] value
+ #
+ # @return [Date]
+ #
+ # @api public
+ def to_date(value)
+ parse_value(::Date, value, __method__)
+ end
+
+ # Coerce given value to DateTime
+ #
+ # @example
+ # coercer[String].to_datetime(string) # => DateTime object
+ #
+ # @param [String] value
+ #
+ # @return [DateTime]
+ #
+ # @api public
+ def to_datetime(value)
+ parse_value(::DateTime, value, __method__)
end
# Coerce value to TrueClass or FalseClass
#
# @example with "T"