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]

Instance Attribute Summary collapse

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

Instance Attribute Details

#raw_cell_setObject (readonly)

Returns the value of attribute raw_cell_set.



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

def raw_cell_set
  @raw_cell_set
end

Class Method Details

.java_to_ruby_value(value, column_type = nil) ⇒ Object



446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/mondrian/olap/result.rb', line 446

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

Instance Method Details

#axes_countObject



13
14
15
# File 'lib/mondrian/olap/result.rb', line 13

def axes_count
  axes.length
end

#axis_full_namesObject



21
22
23
# File 'lib/mondrian/olap/result.rb', line 21

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

#axis_membersObject



25
26
27
# File 'lib/mondrian/olap/result.rb', line 25

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

#axis_namesObject



17
18
19
# File 'lib/mondrian/olap/result.rb', line 17

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



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

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



48
49
50
# File 'lib/mondrian/olap/result.rb', line 48

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

#to_html(options = {}) ⇒ Object

format results in simple HTML table



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
105
106
# File 'lib/mondrian/olap/result.rb', line 62

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



44
45
46
# File 'lib/mondrian/olap/result.rb', line 44

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

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



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

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