Module: Dry::Types::Coercions
- Includes:
- Core::Constants
- Defined in:
- lib/dry/types/coercions.rb,
lib/dry/types/coercions/form.rb,
lib/dry/types/coercions/json.rb
Defined Under Namespace
Instance Method Summary collapse
-
#empty_str?(value) ⇒ Boolean
private
Checks whether String is empty.
- #to_date(input) ⇒ Date, Object
- #to_date_time(input) ⇒ DateTime, Object
- #to_nil(input) ⇒ String?
- #to_time(input) ⇒ Time, Object
Instance Method Details
#empty_str?(value) ⇒ Boolean (private)
Checks whether String is empty
47 48 49 |
# File 'lib/dry/types/coercions.rb', line 47 def empty_str?(value) EMPTY_STRING.eql?(value) end |
#to_date(input) ⇒ Date, Object
15 16 17 18 19 20 |
# File 'lib/dry/types/coercions.rb', line 15 def to_date(input) return input unless input.respond_to?(:to_str) Date.parse(input) rescue ArgumentError input end |
#to_date_time(input) ⇒ DateTime, Object
25 26 27 28 29 30 |
# File 'lib/dry/types/coercions.rb', line 25 def to_date_time(input) return input unless input.respond_to?(:to_str) DateTime.parse(input) rescue ArgumentError input end |
#to_nil(input) ⇒ String?
8 9 10 |
# File 'lib/dry/types/coercions.rb', line 8 def to_nil(input) input unless empty_str?(input) end |
#to_time(input) ⇒ Time, Object
35 36 37 38 39 40 |
# File 'lib/dry/types/coercions.rb', line 35 def to_time(input) return input unless input.respond_to?(:to_str) Time.parse(input) rescue ArgumentError input end |