Class: ENVied::Coercer::ENViedString

Inherits:
Coercible::Coercer::String
  • Object
show all
Defined in:
lib/envied/coercer/envied_string.rb

Instance Method Summary collapse

Instance Method Details

#to_array(str) ⇒ Object



4
5
6
# File 'lib/envied/coercer/envied_string.rb', line 4

def to_array(str)
  str.split(/(?<!\\),/).map{|i| i.gsub(/\\,/,',') }
end

#to_hash(str) ⇒ Object



8
9
10
11
# File 'lib/envied/coercer/envied_string.rb', line 8

def to_hash(str)
  require 'cgi'
  ::CGI.parse(str).map { |key, values| [key, values[0]] }.to_h
end

#to_integer(str) ⇒ Object



18
19
20
21
22
# File 'lib/envied/coercer/envied_string.rb', line 18

def to_integer(str)
  Integer(str)
rescue ArgumentError
  raise_unsupported_coercion(str, __method__)
end

#to_uri(str) ⇒ Object



13
14
15
16
# File 'lib/envied/coercer/envied_string.rb', line 13

def to_uri(str)
  require 'uri'
  ::URI.parse(str)
end