Module: Octo::Segmentation::Helpers

Defined in:
lib/octocore-mongo/segment.rb

Class Method Summary collapse

Class Method Details

.choices_for_dimensions(dimension, enterprise_id) ⇒ Object

Helper method to return valid choices for a given dimension. It tries

to find the values from db first. In case, there is nothing, it
shows some default values, so the dashboard does not look totally
blank.

Parameters:

  • dimension (Fixnum)

    The dimension ID for which choices to be found

  • enterprise_id (String)

    The enterprise ID for which the choices to be found



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/octocore-mongo/segment.rb', line 49

def choices_for_dimensions(dimension, enterprise_id)
  args = {
    enterprise_id: enterprise_id,
    dimension: dimension
  }
  res = Octo::DimensionChoice.where(args)
  choices = Array.new
  if res.count > 0
    choices = res.collect do |r|
      r.column
    end
  elsif dimension_choice.has_key?(dimension)
    func = dimension_choice[dimension]
    choices = self.send(func, enterprise_id)
  end
  mapping_as_choice Hash[Array.new(choices.count) { |i| i }.zip(choices)]
end

.dimensions_as_choiceArray<Hash{Symbol => String }>

Helper method for returning dimensions as choice to be used in the UX

Returns:

  • (Array<Hash{Symbol => String }>)

    The hash containing key :text as the text to display, and another key :id as the id to be used as reference while communicating



32
33
34
# File 'lib/octocore-mongo/segment.rb', line 32

def dimensions_as_choice
  mapping_as_choice dimension_text
end

.logic_operators_as_choiceObject

Returns logic operatos as a choice for operating between dimensions



37
38
39
# File 'lib/octocore-mongo/segment.rb', line 37

def logic_operators_as_choice
  mapping_as_choice logic_text
end

.operators_as_choice(dimension = nil) ⇒ Array<Hash{Symbol => String }>

Helper method for returning operators as a hash to be used in UX

Parameters:

  • dimension (Fixnum) (defaults to: nil)

    The dimension for which the operators are to be fetched

Returns:

  • (Array<Hash{Symbol => String }>)

    The hash containing key :text as the text to display, and another key :id as the id to be used as reference while communicating



24
25
26
# File 'lib/octocore-mongo/segment.rb', line 24

def operators_as_choice(dimension = nil)
  mapping_as_choice operator_text
end