Module: Webhookr::OstructUtils

Defined in:
lib/webhookr/ostruct_utils.rb

Overview

Class Method Summary collapse

Class Method Details

.array_to_ostruct(array) ⇒ Object



23
24
25
# File 'lib/webhookr/ostruct_utils.rb', line 23

def self.array_to_ostruct(array)
  array.map { |r| to_ostruct(r) }
end

.hash_to_ostruct(hash) ⇒ Object



16
17
18
19
20
21
# File 'lib/webhookr/ostruct_utils.rb', line 16

def self.hash_to_ostruct(hash)
  hash.each  do |key, val|
    hash[key] = to_ostruct(val)
  end
  OpenStruct.new(hash)
end

.to_ostruct(obj) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/webhookr/ostruct_utils.rb', line 5

def self.to_ostruct(obj)
  case
  when obj.kind_of?(Hash)
    return hash_to_ostruct(obj)
  when obj.kind_of?(Array)
    return array_to_ostruct(obj)
  else
    return obj
  end
end