Class: XMLA::Cube

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#catalogObject (readonly)

Returns the value of attribute catalog.



15
16
17
# File 'lib/cube/cube.rb', line 15

def catalog
  @catalog
end

#queryObject (readonly)

Returns the value of attribute query.



15
16
17
# File 'lib/cube/cube.rb', line 15

def query
  @query
end

Class Method Details

.execute(query, catalog = XMLA.catalog) ⇒ Object



17
18
19
# File 'lib/cube/cube.rb', line 17

def Cube.execute(query, catalog = XMLA.catalog)
  OlapResult.new(Cube.new(query, catalog).as_table)
end

.execute_members(query, catalog = XMLA.catalog) ⇒ Object



21
22
23
# File 'lib/cube/cube.rb', line 21

def Cube.execute_members(query, catalog = XMLA.catalog)
  Cube.new(query, catalog).axes
end

.execute_scalar(query, catalog = XMLA.catalog) ⇒ Object



25
26
27
# File 'lib/cube/cube.rb', line 25

def Cube.execute_scalar(query, catalog = XMLA.catalog)
  BigDecimal.new Cube.new(query, catalog).as_table[0][:value]
end

Instance Method Details

#as_tableObject



29
30
31
32
33
34
35
36
# File 'lib/cube/cube.rb', line 29

def as_table
  return [table] if y_size == 0
  clean_table(table).reduce([]) { |result, row|
    flat_row = row.flatten
    result << flat_row unless flat_row.all?(&:blank?)
    result
  }
end

#axesObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/cube/cube.rb', line 38

def axes
  axes = all_axes.select { |axe| axe[:@name] != "SlicerAxis" }
  @axes ||= axes.reduce([]) do |result, axe|
    result << tuple(axe).reduce([]) { |y, member|
      data = (member[0] == :member) ? member[1] : member[:member]
      if ( data.class == Hash || data.size == 1 )
        # y << [data[:caption].strip].flatten
        y << [data].flatten
        # y << [Hash[*data.map{|d| [d.first,d.last.to_s]}.flatten]].flatten
      else
        y << data.select { |item_data| item_data.class == Hash }.reduce([]) do |z,item_data|
          z << [item_data].flatten
          # z << item_data[:caption].strip
        end
      end
    }
  end
end