Class: Tmdb::Struct

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/tmdb/struct.rb

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Struct

Returns a new instance of Struct.



3
4
5
6
7
8
9
10
11
# File 'lib/tmdb/struct.rb', line 3

def initialize(data=nil)
  @table = {}

  if data
    data.each do |k,v|
      self[k] = analyze_value(v)
    end
  end
end

Instance Method Details

#analyze_value(v) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tmdb/struct.rb', line 13

def analyze_value(v)
  case v
    when Hash
      self.class.new(v)
    when Array
      v.map do |element|
        analyze_value(element)
      end
    else
      v
  end
end