Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

process array

  • Loading branch information...
commit 2c6f35b5401633b1d1d82019a9d70113f3cd121b 1 parent 39eab03
@rimian rimian authored
Showing with 10 additions and 13 deletions.
  1. +0 −3  lib/switchvox.rb
  2. +10 −10 lib/switchvox/base.rb
View
3  lib/switchvox.rb
@@ -1,9 +1,6 @@
$:.unshift(File.dirname(__FILE__)) unless
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
-require 'switchvox/hash'
-require 'switchvox/array'
-require 'switchvox/object'
require 'switchvox/net_http_digest_auth'
require 'switchvox/base'
View
20 lib/switchvox/base.rb
@@ -84,17 +84,17 @@ def json_parse(body)
convert_to_obj(json["response"]["result"])
end
- def convert_to_obj(hash)
- hash.each do |x, y|
- unless y.is_a? String
- y.map! do |v|
- convert_to_obj(v)
- end
- end
+ def convert_to_obj(arg)
+ if arg.is_a? Hash
+ arg.each { |k, v| convert_to_obj(v) }
+ o = OpenStruct.new
+ o.marshal_load Hash[arg.map { |k, v| [k.to_sym, v] }]
+ return o
+ elsif arg.is_a? Array
+ arg.map! { |v| convert_to_obj(v) }
+ else
+ arg
end
- o = OpenStruct.new
- o.marshal_load Hash[hash.map {|k, v| [k.to_sym, v] }]
- o
end
protected
Please sign in to comment.
Something went wrong with that request. Please try again.