Class: Keymaker::CypherResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/keymaker/parsers/cypher_response_parser.rb

Class Method Summary collapse

Class Method Details

.parse(response_body) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/keymaker/parsers/cypher_response_parser.rb', line 4

def self.parse(response_body)
  response_body.data.map do |result|
    if response_body.columns.one? && result.first.kind_of?(Hashie::Mash)
      result.first.data
    else
      translate_response(response_body, result)
    end
  end
end

.sanitized_column_names(response_body) ⇒ Object



18
19
20
21
22
# File 'lib/keymaker/parsers/cypher_response_parser.rb', line 18

def self.sanitized_column_names(response_body)
  response_body.columns.map do |column|
    column[/[^\.]+$/]
  end
end

.translate_response(response_body, result) ⇒ Object



14
15
16
# File 'lib/keymaker/parsers/cypher_response_parser.rb', line 14

def self.translate_response(response_body, result)
  Hashie::Mash.new(Hash[sanitized_column_names(response_body).zip(result)])
end