class Cl::Cast::Cast

Constants

FALSE
TRUE

Public Instance Methods

apply() click to toggle source
# File lib/cl/cast.rb, line 7
def apply
  return send(type) if respond_to?(type, true)
  raise ArgumentError, "Unknown type: #{type}"
rescue ::ArgumentError => e
  raise ArgumentError.new(:wrong_type, value.inspect, type)
end

Private Instance Methods

array() click to toggle source
# File lib/cl/cast.rb, line 16
def array
  Array(value).compact.flatten.map { |value| split(value) }.flatten.compact
end
bool()
Alias for: boolean
boolean() click to toggle source
# File lib/cl/cast.rb, line 25
def boolean
  return true  if value.to_s =~ TRUE
  return false if value.to_s =~ FALSE
  !!value
end
Also aliased as: bool, flag
flag()
Alias for: boolean
float() click to toggle source
# File lib/cl/cast.rb, line 38
def float
  Float(value) if value
end
int() click to toggle source
# File lib/cl/cast.rb, line 33
def int
  Integer(value) if value
end
Also aliased as: integer
integer()
Alias for: int
separator() click to toggle source
# File lib/cl/cast.rb, line 46
def separator
  opts[:separator]
end
split(value) click to toggle source
# File lib/cl/cast.rb, line 42
def split(value)
  separator ? value.to_s.split(separator) : value
end
str()
Alias for: string
string() click to toggle source
# File lib/cl/cast.rb, line 20
def string
  value.to_s unless value.to_s.empty?
end
Also aliased as: str