module Tablecloth::Coercions
Coercion functions for common types
@api public
Constants
- BOOLEAN_MAP
- FALSE_VALUES
- TRUE_VALUES
Public Instance Methods
Coerce value into a boolean
@example
Transproc(:to_boolean)["true"] # => true Transproc(:to_boolean)["f"] # => false
@param [Object] value The input value
@return [TrueClass,FalseClass]
@api public
# File lib/tablecloth/coercions.rb, line 110 def to_boolean(value, _world) BOOLEAN_MAP.fetch(value) end
Coerce value into a date
@example
Transproc(:to_date)["2015-04-14"] # => #<Date: 2015-04-14 ((2457127j,0s,0n),+0s,2299161j)>
@param [Object] value The input value
@return [Date]
@api public
# File lib/tablecloth/coercions.rb, line 125 def to_date(value, _world) Date.parse(value) end
Coerce value into a datetime
@example
Transproc(:to_datetime)["2015-04-14 12:01:45", nothing] # => #<DateTime: 2015-04-14T12:01:45+00:00 ((2457127j,43305s,0n),+0s,2299161j)>
@param [Object] value The input value @param [World] world Cucumber world object
@return [DateTime]
@api public
# File lib/tablecloth/coercions.rb, line 156 def to_datetime(value, _world) DateTime.parse(value) end
Coerce value into a decimal
@example
Transproc(:to_decimal)[1.2] # => #<BigDecimal:7fca32acea50,"0.12E1",18(36)>
@param [Object] value The input value
@return [Decimal]
@api public
# File lib/tablecloth/coercions.rb, line 93 def to_decimal(value, _world) value.to_d end
Coerce value into a float
@example
Transproc(:to_float)["1.2"] # => 1.2
@param [Object] value The input value
@return [Float]
@api public
# File lib/tablecloth/coercions.rb, line 78 def to_float(value, _world) value.to_f end
Coerce value into a integer
@example
Transproc(:to_integer)["1"] # => 1
@param [Object] value The input value
@return [Integer]
@api public
# File lib/tablecloth/coercions.rb, line 63 def to_integer(value, _world) value.to_i end
Coerce value into a string
@example
Transproc(:to_string)[1] # => "1"
@param [Object] value The input value
@return [String]
@api public
# File lib/tablecloth/coercions.rb, line 33 def to_string(value, _world) value.to_s end
Coerce value into a symbol
@example
Transproc(:to_symbol)["foo"] # => :foo
@param [Object] value The input value
@return [Symbol]
@api public
# File lib/tablecloth/coercions.rb, line 48 def to_symbol(value, _world) value.to_sym end
Coerce value into a time
@example
Transproc(:to_time)["2015-04-14 12:01:45"] # => 2015-04-14 12:01:45 +0200
@param [Object] value The input value
@return [Time]
@api public
# File lib/tablecloth/coercions.rb, line 140 def to_time(value, _world) Time.parse(value) end