Module: Reddit::Base::Helpers

Defined in:
lib/reddit/base/helpers.rb

Class Method Summary collapse

Class Method Details

.simplify(json) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/reddit/base/helpers.rb', line 4

def self.simplify(json)
  return json unless json.is_a? Hash

  if json['data']
    json['data']['kind'] = json['kind'] if json['data'].is_a? Hash
    json = simplify json['data']
  elsif json['children']
    json['children'] = json['children'].map { |child| simplify child }
  else
    json.keys.each do |key|
      json[key] = simplify json[key]
    end
  end

  json
end