Class: Konfig::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/konfig/utils.rb

Class Method Summary collapse

Class Method Details

.coerce(value) ⇒ Object

coreces the given value (string) into the best possible type

Raises:

  • (UnsupportedValueType)


36
37
38
39
40
41
42
43
44
# File 'lib/konfig/utils.rb', line 36

def self.coerce(value)
  # assume a float first
  DESERIALIZERS.each do |deseralizer|
    result = deseralizer.call(value)
    return result unless result == NIL_VALUE
  end

  raise UnsupportedValueType, "'#{value}' is unsupported type"
end

.remove_quotations(str) ⇒ Object



46
47
48
49
50
# File 'lib/konfig/utils.rb', line 46

def self.remove_quotations(str)
  str = str.slice(1..-1) if str.start_with?('"') || str.start_with?('\'')
  str = str.slice(0..-2) if str.end_with?('"') || str.end_with?('\'')
  return str
end