Class: BasicYoutube::YoutubeObject

Inherits:
Object
  • Object
show all
Defined in:
lib/basic_youtube/youtube_object.rb

Direct Known Subclasses

Channel, Video

Instance Method Summary collapse

Instance Method Details

#recursive_hash_access(dynamic_methods, base, key) ⇒ Object

Recursively assigns methods to the instance allowing for access to nested attributes of the entry hash, (eg, c.statistics => c.entry and c.view_count => c.entry[“viewCount”])



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/basic_youtube/youtube_object.rb', line 9

def recursive_hash_access dynamic_methods, base, key
  if key.respond_to? :keys
    key.each do |k,v|
      recursive_hash_access(dynamic_methods, base, k)
      v=[v] unless v.kind_of?(Array)
      v.each do |v1|
        recursive_hash_access(dynamic_methods, base[k.to_s.camelcase(:lower)], v1)
      end
    end
  else
    value = base[key.to_s.camelcase(:lower)]
    begin
      value = value.number? ? value.to_i : Date.parse(value)
    rescue
    end
    dynamic_methods[key] = value
  end
end