class XMLA::Cube
Attributes
catalog[R]
query[R]
Public Class Methods
execute(query, catalog = XMLA.catalog)
click to toggle source
# File lib/cube/cube.rb, line 17 def Cube.execute(query, catalog = XMLA.catalog) OlapResult.new(Cube.new(query, catalog).as_table) end
execute_scalar(query, catalog = XMLA.catalog)
click to toggle source
# File lib/cube/cube.rb, line 21 def Cube.execute_scalar(query, catalog = XMLA.catalog) BigDecimal.new Cube.new(query, catalog).as_table[0] end
new(query, catalog)
click to toggle source
# File lib/cube/cube.rb, line 63 def initialize(query, catalog) @query = query @catalog = catalog @response = get_response self end
Private Class Methods
request_body(query, catalog)
click to toggle source
# File lib/cube/cube.rb, line 132 def Cube.request_body(query, catalog) <<-REQUEST <Command> <Statement> <![CDATA[ #{query} ]]> </Statement> </Command> <Properties> <PropertyList> <Catalog>#{catalog}</Catalog> <Format>Multidimensional</Format> <AxisFormat>TupleFormat</AxisFormat> </PropertyList> </Properties> REQUEST end
Public Instance Methods
as_table()
click to toggle source
# File lib/cube/cube.rb, line 25 def as_table return [table] if y_size == 0 clean_table(table, y_size).reduce([]) { |result, row| result << row.flatten } end
Private Instance Methods
all_axes()
click to toggle source
# File lib/cube/cube.rb, line 112 def all_axes @response.to_hash[:execute_response][:return][:root][:axes][:axis] end
axes()
click to toggle source
# File lib/cube/cube.rb, line 47 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 else y << data.select { |item_data| item_data.class == Hash }.reduce([]) do |z,item_data| z << item_data[:caption].strip end end } end end
cell_data()
click to toggle source
# File lib/cube/cube.rb, line 98 def cell_data cell_data = @response.to_hash[:execute_response][:return][:root][:cell_data] return [""] if cell_data.nil? @data ||= cell_data.reduce([]) do |data, cell| cell[1].reduce(data) do |data, value| data << (value.class == Hash ? value[:value] : value[1] ) end end end
clean_table(table, number_of_colums)
click to toggle source
cleanup table so items don’t repeat (if they are same)
# File lib/cube/cube.rb, line 82 def clean_table(table, number_of_colums) above_row = [] #filter if they are not last column, and they are same as the item on the row above table.reduce([]) { |result, row| result << row.each_with_index.map do |item,i| if i == number_of_colums item else item == above_row[i] ? '' : item end end above_row = row result } end
get_response()
click to toggle source
# File lib/cube/cube.rb, line 70 def get_response client = Savon::Client.new do wsdl.document = File.expand_path("../../wsdl/xmla.xml", __FILE__) wsdl.endpoint = XMLA.endpoint end @response = client.request :execute, xmlns:"urn:schemas-microsoft-com:xml-analysis" do soap.body = Cube.request_body(query, catalog) end end
header()
click to toggle source
# File lib/cube/cube.rb, line 43 def header [ ( (0..y_size - 1).reduce([]) { |header| header << '' } << x_axe).flatten ] end
table()
click to toggle source
header and rows
# File lib/cube/cube.rb, line 33 def table if (header.size == 1 && y_size == 0) cell_data[0] else (0...y_axe.size).reduce(header) do |result, j| result << ( y_axe[j] + (0...x_size).map { |i| "#{cell_data[i + j]}" }) end end end
tuple(axe)
click to toggle source
# File lib/cube/cube.rb, line 108 def tuple axe axe[:tuples].nil? ? [] : axe[:tuples][:tuple] end
x_axe()
click to toggle source
# File lib/cube/cube.rb, line 116 def x_axe @x_axe ||= axes[0] end
x_size()
click to toggle source
# File lib/cube/cube.rb, line 128 def x_size x_axe.size end
y_axe()
click to toggle source
# File lib/cube/cube.rb, line 120 def y_axe @y_axe ||= axes[1] end
y_size()
click to toggle source
# File lib/cube/cube.rb, line 124 def y_size (y_axe.nil? || y_axe[0].nil?) ? 0 : y_axe[0].size end