Module: Dry::Types::Coercions::JSON
- Extended by:
- Dry::Types::Coercions
- Defined in:
- lib/dry/types/coercions/json.rb
Overview
JSON-specific coercions
Class Method Summary collapse
- .to_date(input, &block) ⇒ Date, Object extended from Dry::Types::Coercions
- .to_date_time(input, &block) ⇒ DateTime, Object extended from Dry::Types::Coercions
- .to_decimal(input, &_block) ⇒ BigDecimal?
-
.to_nil(input, &_block) ⇒ nil
If the input is nil.
- .to_symbol(input, &block) ⇒ Symbol, Object extended from Dry::Types::Coercions
- .to_time(input, &block) ⇒ Time, Object extended from Dry::Types::Coercions
Class Method Details
.to_date(input, &block) ⇒ Date, Object Originally defined in module Dry::Types::Coercions
.to_date_time(input, &block) ⇒ DateTime, Object Originally defined in module Dry::Types::Coercions
.to_decimal(input, &_block) ⇒ BigDecimal?
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dry/types/coercions/json.rb', line 41 def self.to_decimal(input, &_block) if input.is_a?(::Float) input.to_d else BigDecimal(input) end rescue ArgumentError, TypeError if block_given? yield else raise CoercionError, "#{input} cannot be coerced to decimal" end end |
.to_nil(input, &_block) ⇒ nil
Returns if the input is nil.
24 25 26 27 28 29 30 31 32 |
# File 'lib/dry/types/coercions/json.rb', line 24 def self.to_nil(input, &_block) if input.nil? nil elsif block_given? yield else raise CoercionError, "#{input.inspect} is not nil" end end |