Class: Mondrian::OLAP::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/mondrian/olap/result.rb

Defined Under Namespace

Classes: DrillThrough

Constant Summary collapse

AXIS_SYMBOLS =
[:column, :row, :page, :section, :chapter]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, raw_cell_set) ⇒ Result

Returns a new instance of Result.



6
7
8
9
# File 'lib/mondrian/olap/result.rb', line 6

def initialize(connection, raw_cell_set)
  @connection = connection
  @raw_cell_set = raw_cell_set
end

Class Method Details

.java_to_ruby_value(value, column_type = nil) ⇒ Object



386
387
388
389
390
391
392
393
394
395
# File 'lib/mondrian/olap/result.rb', line 386

def self.java_to_ruby_value(value, column_type = nil)
  case value
  when Numeric, String
    value
  when Java::JavaMath::BigDecimal
    BigDecimal(value.to_s)
  else
    value
  end
end

Instance Method Details

#axes_countObject



11
12
13
# File 'lib/mondrian/olap/result.rb', line 11

def axes_count
  axes.length
end

#axis_full_namesObject



19
20
21
# File 'lib/mondrian/olap/result.rb', line 19

def axis_full_names
  @axis_full_names ||= axis_positions(:getUniqueName)
end

#axis_membersObject



23
24
25
# File 'lib/mondrian/olap/result.rb', line 23

def axis_members
  @axis_members ||= axis_positions(:to_member)
end

#axis_namesObject



15
16
17
# File 'lib/mondrian/olap/result.rb', line 15

def axis_names
  @axis_names ||= axis_positions(:getName)
end

#drill_through(params = {}) ⇒ Object

Specify drill through cell position, for example, as

:row => 0, :cell => 1

Specify max returned rows with :max_rows parameter Specify returned fields (as list of MDX levels and measures) with :return parameter Specify measures which at least one should not be empty (NULL) with :nonempty parameter



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/mondrian/olap/result.rb', line 111

def drill_through(params = {})
  Error.wrap_native_exception do
    cell_params = []
    axes_count.times do |i|
      axis_symbol = AXIS_SYMBOLS[i]
      raise ArgumentError, "missing position #{axis_symbol.inspect}" unless axis_position = params[axis_symbol]
      cell_params << Java::JavaLang::Integer.new(axis_position)
    end
    raw_cell = @raw_cell_set.getCell(cell_params)
    DrillThrough.from_raw_cell(raw_cell, params)
  end
end

#formatted_values(*axes_sequence) ⇒ Object



46
47
48
# File 'lib/mondrian/olap/result.rb', line 46

def formatted_values(*axes_sequence)
  values_using(:getFormattedValue, axes_sequence)
end

#to_html(options = {}) ⇒ Object

format results in simple HTML table



60
61
62
63
64
65
66
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
# File 'lib/mondrian/olap/result.rb', line 60

def to_html(options = {})
  case axes_count
  when 1
    builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |doc|
      doc.table do
        doc.tr do
          column_full_names.each do |column_full_name|
            column_full_name = column_full_name.join(',') if column_full_name.is_a?(Array)
            doc.th column_full_name, :align => 'right'
          end
        end
        doc.tr do
          (options[:formatted] ? formatted_values : values).each do |value|
            doc.td value, :align => 'right'
          end
        end
      end
    end
    builder.doc.to_html
  when 2
    builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |doc|
      doc.table do
        doc.tr do
          doc.th
          column_full_names.each do |column_full_name|
            column_full_name = column_full_name.join(',') if column_full_name.is_a?(Array)
            doc.th column_full_name, :align => 'right'
          end
        end
        (options[:formatted] ? formatted_values : values).each_with_index do |row, i|
          doc.tr do
            row_full_name = row_full_names[i].is_a?(Array) ? row_full_names[i].join(',') : row_full_names[i]
            doc.th row_full_name, :align => 'left'
            row.each do |cell|
              doc.td cell, :align => 'right'
            end
          end
        end
      end
    end
    builder.doc.to_html
  else
    raise ArgumentError, "just columns and rows axes are supported"
  end
end

#values(*axes_sequence) ⇒ Object



42
43
44
# File 'lib/mondrian/olap/result.rb', line 42

def values(*axes_sequence)
  values_using(:getValue, axes_sequence)
end

#values_using(values_method, axes_sequence = []) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/mondrian/olap/result.rb', line 50

def values_using(values_method, axes_sequence = [])
  if axes_sequence.empty?
    axes_sequence = (0...axes_count).to_a.reverse
  elsif axes_sequence.size != axes_count
    raise ArgumentError, "axes sequence size is not equal to result axes count"
  end
  recursive_values(values_method, axes_sequence, 0)
end