Class: Mondrian::OLAP::Cube

Inherits:
Object
  • Object
show all
Defined in:
lib/mondrian_rest/mondrian_ext.rb

Instance Method Summary collapse

Instance Method Details

#to_hObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mondrian_rest/mondrian_ext.rb', line 5

def to_h
  # gather dimensions
  dimensions = self.dimensions
               .find_all { |d| d.dimension_type != :measures }
               .map { |d|
    {
      :name => d.name,
      :caption => d.caption,
      :type => d.dimension_type,
      :annotations => d.annotations,
      :hierarchies => d.hierarchies.map { |h|
        {
          :name => h.name,
          :has_all => h.has_all?,
          :all_member_name => h.all_member_name,
          :levels => h.levels.map { |l|
            {
              :name => l.name,
              :full_name => l.full_name,
              :caption => l.caption
            }
          }
        }
      }
    }
  }

  return {
    :name => self.name,
    :annotations => self.annotations,
    :dimensions => dimensions,
    :measures => self.dimensions
                .find(&:measures?)
                .hierarchy
                .levels.first
                .members
                .find_all(&:visible?)
                .map do |m|
      {
        :name => m.name,
        :caption => m.caption,
        :annotations => m.annotations,
        :full_name => m.full_name
      }
    end
  }
end