Class Coercible::Coercer::String
In: lib/coercible/coercer/string.rb
Parent: Object

Coerce String values

Methods

Constants

TRUE_VALUES = %w[ 1 on t true y yes ].freeze
FALSE_VALUES = %w[ 0 off f false n no ].freeze
BOOLEAN_MAP = ::Hash[ TRUE_VALUES.product([ true ]) + FALSE_VALUES.product([ false ]) ].freeze
INTEGER_REGEXP = /[-+]?(?:[0-9]\d*)/.freeze
EXPONENT_REGEXP = /(?:[eE][-+]?\d+)/.freeze
FRACTIONAL_REGEXP = /(?:\.\d+)/.freeze
NUMERIC_REGEXP = /\A( #{INTEGER_REGEXP}#{FRACTIONAL_REGEXP}?#{EXPONENT_REGEXP}? | #{FRACTIONAL_REGEXP}#{EXPONENT_REGEXP}? )\z/x.freeze

Attributes

boolean_map  [R]  Return boolean map from the config

@return [::Hash]

@api private

Public Class methods

Return default configuration for string coercer type

@return [Configuration]

@api private

Initialize a new string coercer instance

@param [Coercer]

@param [Configuration]

@return [undefined]

@api private

Public Instance methods

Coerce value to TrueClass or FalseClass

@example with "T"

  coercer[String].to_boolean('T')  # => true

@example with "F"

  coercer[String].to_boolean('F')  # => false

@param [to_s]

@return [Boolean]

@api public

Coerce give value to a constant

@example

  coercer[String].to_constant('String') # => String

@param [String] value

@return [Object]

@api public

Coerce given value to Date

@example

  coercer[String].to_date(string)  # => Date object

@param [String] value

@return [Date]

@api public

Coerce given value to DateTime

@example

  coercer[String].to_datetime(string)  # => DateTime object

@param [String] value

@return [DateTime]

@api public

Coerce value to decimal

@example

  coercer[String].to_decimal('1.2')  # => #<BigDecimal:b72157d4,'0.12E1',8(8)>

@param [Object] value

@return [BigDecimal]

@api public

Coerce value to float

@example

  coercer[String].to_float('1.2')  # => 1.2

@param [Object] value

@return [Float]

@api public

Coerce value to integer

@example

  coercer[String].to_integer('1')  # => 1

@param [Object] value

@return [Integer]

@api public

Coerce give value to a symbol

@example

  coercer[String].to_symbol('string') # => :string

@param [String] value

@return [Symbol]

@api public

Coerce given value to Time

@example

  coercer[String].to_time(string)  # => Time object

@param [String] value

@return [Time]

@api public

[Validate]