module Snowly::Transformer
Constants
- MAP
Boolean fields are mapped to string because the tracker sends '1' or '0' in the query string. The actual conversion to boolean happens during the enrichment phase.
Public Instance Methods
convert(value, type)
click to toggle source
Tries to cast or parse each value so they can be properly validated by json-schema If the casting fails, leaves the value as string and it will be caught by the valication @param value [String] @param type [String] the intended param type
# File lib/snowly/transformer.rb, line 101 def convert(value, type) begin case type when 'json' then JSON.parse(value) when 'base64' then JSON.parse(Base64.decode64(value)) when 'integer' then Integer(value) when 'number' then Float(value) else value.to_s end rescue ArgumentError value.to_s end end
transform(parsed_query)
click to toggle source
Transforms the request params into column names @param parsed_query [Hash] hash using parameter names for keys @return [Hash] hash using column names for keys
# File lib/snowly/transformer.rb, line 87 def transform(parsed_query) parsed_query.inject({}) do |all, (key, value)| if node = MAP[key] field = node[:field] all[field] = convert(value, node[:type]) end all end end