Class: Basecampeverest::Convert

Inherits:
Object
  • Object
show all
Defined in:
lib/basecampeverest/convert.rb

Instance Method Summary collapse

Instance Method Details

#convert_to_ostruct_recursive(obj, options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/basecampeverest/convert.rb', line 14

def convert_to_ostruct_recursive(obj, options)
  result = obj
  if result.is_a? Hash
    result = result.dup.with_sym_keys
    result.each  do |key, val| 
      result[key] = convert_to_ostruct_recursive(val, options) unless options[:exclude].try(:include?, key)
    end
    result = OpenStruct.new result       
  elsif result.is_a? Array
     result = result.map { |r| convert_to_ostruct_recursive(r, options) }
  end
  return result
end

#to_ostruct_recursive(options) ⇒ Basecampeverest::Project

convert an array into a nested OpenStruct

Parameters:

Returns:



10
11
12
# File 'lib/basecampeverest/convert.rb', line 10

def to_ostruct_recursive(options)
  convert_to_ostruct_recursive(self, options) 
end