Class: HAStats::Responses::CSV

Inherits:
Base
  • Object
show all
Defined in:
lib/hastats/responses/csv.rb

Instance Attribute Summary

Attributes inherited from Base

#parsed, #raw

Instance Method Summary collapse

Methods inherited from Base

#initialize, #to_json

Constructor Details

This class inherits a constructor from HAStats::Responses::Base

Instance Method Details

#parseObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hastats/responses/csv.rb', line 5

def parse
  self.parsed = []
  header = nil
  self.raw.each do |row|
    row = CSV.parse(row.gsub(/#*\s*/, '').strip).first
    if row && header
      result = {}
      header.each_index do |i|
        result[header[i]] = row[i]
      end
      self.parsed << result
    elsif row
      header = row
    end
  end
  self.parsed
end