Class: Rubiks::Mondrian::CellSet

Inherits:
Object
  • Object
show all
Defined in:
lib/rubiks/mondrian/cell_set.rb

Instance Method Summary collapse

Constructor Details

#initialize(raw_cell_set) ⇒ CellSet

Returns a new instance of CellSet.



7
8
9
# File 'lib/rubiks/mondrian/cell_set.rb', line 7

def initialize(raw_cell_set)
  @raw_cell_set = raw_cell_set
end

Instance Method Details

#axesObject



53
54
55
# File 'lib/rubiks/mondrian/cell_set.rb', line 53

def axes
  @axes ||= @raw_cell_set.getAxes
end

#axis_string(axis) ⇒ Object



61
62
63
64
65
# File 'lib/rubiks/mondrian/cell_set.rb', line 61

def axis_string(axis)
  axis[:tuples].map do |tuple|
    members = tuple[:members].map{ |member| member[:path] }.join(',')
  end.join('|')
end

#cellsObject



33
34
35
# File 'lib/rubiks/mondrian/cell_set.rb', line 33

def cells
  raw_cells.flatten
end

#column_axisObject



45
46
47
# File 'lib/rubiks/mondrian/cell_set.rb', line 45

def column_axis
  result_axes.first
end

#cube_nameObject



37
38
39
# File 'lib/rubiks/mondrian/cell_set.rb', line 37

def cube_name
  @raw_cell_set..cube.name
end

#filter_axisObject



41
42
43
# File 'lib/rubiks/mondrian/cell_set.rb', line 41

def filter_axis
  generate_axis(@raw_cell_set.filter_axis)
end

#generate_axis(axis) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rubiks/mondrian/cell_set.rb', line 67

def generate_axis(axis)
  tuples = axis.getPositions.map do |position|

    members = position.getMembers.map do |raw_member|
      member = ::Rubiks::Mondrian::Member.new(raw_member)

      names = [raw_member.level.name]
      names << raw_member.level.hierarchy.name.split('.').last
      names << raw_member.level.hierarchy.dimension.name

      level_unique_name = names.reverse.flatten.map{ |str| "[#{str}]" }.join('.')
      member_unique_name = "#{level_unique_name}.[#{raw_member.name}]"

      path_name = '/' + raw_member.unique_name.gsub(/\]\.\[/, '/')[1...-1]

      {
        :name => raw_member.name,
        :unique_name => generate_unique_name(member_unique_name),
        :level_name => generate_unique_name(level_unique_name),
        :path => path_name,
        :level_depth => raw_member.depth,
        :child_count => member.children.length,
        :is_all_member => member.all_member?,
        :is_drillable => member.drillable?
      }
    end

    members.compact!

    if members.present?
      {:members => members}
    end
  end

  tuples.compact!

  if tuples.present?
    {
      :name => axis.axis_ordinal.name,
      :tuples => tuples
    }
  else
    nil
  end
end

#generate_unique_name(string) ⇒ Object

[Date.YQMD] - Mondrian's hierarchy [Logins].[Date].[YQMD] - needed output



115
116
117
118
119
120
121
122
123
124
# File 'lib/rubiks/mondrian/cell_set.rb', line 115

def generate_unique_name(string)
  cube_name = @raw_cell_set..cube.name
  dimension_hierarchy_regexp = /\[([^\]]+)\.([^\]]+)\]/
  formatted_string = string.
                      gsub(dimension_hierarchy_regexp, '[\1].[\2]').
                      gsub(/\[Measures\]\.\[Measures\]/, '[Measures]').
                      gsub(/\.\[MeasuresLevel\]/, '')

  "[#{cube_name}].#{formatted_string}"
end

#inspectObject



15
16
17
18
19
20
21
22
# File 'lib/rubiks/mondrian/cell_set.rb', line 15

def inspect
  axes_strings  = []
  axes_strings << "column_axis=#{axis_string(column_axis)}"
  axes_strings << "row_axis=#{axis_string(row_axis)}" if row_axis
  axes_strings << "filter_axis=#{axis_string(filter_axis)}" if filter_axis

  "#<#{self.class} cube=#{cube_name} #{axes_strings.join(' ')}>"
end

#raw_cellsObject



126
127
128
129
# File 'lib/rubiks/mondrian/cell_set.rb', line 126

def raw_cells
  axes_sequence = (0...axes.size).to_a.reverse
  recursive_values(axes_sequence, 0)
end

#recursive_values(axes_sequence, current_index, cell_params = []) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/rubiks/mondrian/cell_set.rb', line 131

def recursive_values(axes_sequence, current_index, cell_params=[])
  if axis_number = axes_sequence[current_index]
    (0...axes[axis_number].getPositions.size).map do |i|
      cell_params[axis_number] = Java::JavaLang::Integer.new(i)
      recursive_values(axes_sequence, current_index + 1, cell_params)
    end
  else
    cell = @raw_cell_set.getCell(cell_params)
    {
      :value => cell.value,
      :formatted_value => cell.formatted_value
    }
  end
end

#result_axesObject



57
58
59
# File 'lib/rubiks/mondrian/cell_set.rb', line 57

def result_axes
  axes.map{ |raw_axis| generate_axis(raw_axis) }
end

#row_axisObject



49
50
51
# File 'lib/rubiks/mondrian/cell_set.rb', line 49

def row_axis
  result_axes[1]
end

#to_hashObject



24
25
26
27
28
29
30
31
# File 'lib/rubiks/mondrian/cell_set.rb', line 24

def to_hash
  {
    :cube_name => cube_name,
    :cells => cells,
    :axes => result_axes,
    :filter_axis => filter_axis
  }.delete_if{ |k,v| v.blank? }
end

#to_sObject



11
12
13
# File 'lib/rubiks/mondrian/cell_set.rb', line 11

def to_s
  "#<#{self.class}>"
end