Module: OSvCRuby::NormalizeModule

Included in:
AnalyticsReportResults, QueryResults
Defined in:
lib/osvc_ruby/modules/normalize_module.rb

Class Method Summary collapse

Class Method Details

.iterate_through_rows(item) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/osvc_ruby/modules/normalize_module.rb', line 36

def iterate_through_rows(item)

  results_array = []

       item['rows'].each_with_index do |row,_row_i|

              obj_hash = {}
              
              item['columnNames'].each_with_index do |column,i|

                     obj_hash[column] = if !row[i].nil? && row[i].is_i? == true then row[i].to_i else row[i] end

              end

        results_array.push(obj_hash)

       end

       results_array

end

.normalize(input) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/osvc_ruby/modules/normalize_module.rb', line 9

def normalize(input)

  if input.code.to_i == 404

    input.body

  else

    json_input = JSON.parse(input.body)

    final_hash = []

    json_input['items'].each do |item|
      results_array = iterate_through_rows(item)             
          final_hash.push(results_array)
    end

    if final_hash.size === 1
      final_hash = final_hash.flatten!
    end

    final_hash.to_json

  end

end