Class: MixReader::People

Inherits:
Base
  • Object
show all
Defined in:
lib/mix_reader/people.rb

Constant Summary collapse

JQL_SCRIPT_MAIN =
'PARAMS function main(){ SCRIPT_QUERY }'
JQL_SCRIPT_CLASS =
'return People()'
JQL_SCRIPT_FILTER =
'.filter(function(entity){ return FILTER_STRING });'
JQL_SCRIPT_PARAMS =
"params = PARAMS_HASH;"

Constants inherited from Base

Base::MIXPANEL_JQL_URL

Instance Attribute Summary

Attributes inherited from Base

#filters, #options, #script

Instance Method Summary collapse

Methods inherited from Base

#initialize, query, #query

Constructor Details

This class inherits a constructor from MixReader::Base

Instance Method Details

#build_scriptObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/mix_reader/people.rb', line 8

def build_script
  params = ""
  query_string = JQL_SCRIPT_CLASS

  if filters.any?
    query_string += JQL_SCRIPT_FILTER.sub("FILTER_STRING", filter_string)
    params = JQL_SCRIPT_PARAMS.sub("PARAMS_HASH", filters.to_json)
  end
  @script = JQL_SCRIPT_MAIN.sub("SCRIPT_QUERY", query_string).sub("PARAMS", params)
end

#filter_stringObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/mix_reader/people.rb', line 19

def filter_string
  return "" unless filters.any?

  equal_filters = filters.clone

  predicates =  equal_filters
                 .map{ |k, v| "entity.properties.#{m_key(k.to_s)} == params.#{k}" }

  predicates.join("&&") + ";"
end