Class: PlaidObject

Inherits:
Object
  • Object
show all
Defined in:
lib/plaid/plaid_object.rb

Direct Known Subclasses

PlaidError

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ PlaidObject

Returns a new instance of PlaidObject.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/plaid/plaid_object.rb', line 3

def initialize(hash)
  hash.keys.each do |key|
    self.class.send(:define_method, "#{key}") do
      instance_variable_get("@#{key}")
    end

    if hash[key].is_a? Array
      arr = []
      hash[key].each do |chunk|
        if chunk.is_a? Hash
          arr <<  PlaidObject.new(chunk)
        else
          arr << chunk
        end
      end
      instance_variable_set("@#{key}", arr)
    elsif hash[key].is_a? Hash
      h = hash[key]
      instance_variable_set("@#{key}", h)
    else
      eval("@#{key} = '#{encode(hash[key].to_s)}'")
    end
  end

end

Instance Method Details

#encode(str) ⇒ Object



29
30
31
# File 'lib/plaid/plaid_object.rb', line 29

def encode(str)
  str.gsub("'", "")
end