Sha256: dfc31da61db57cffe4b34a002ea754be7ebc2f410cd7e621fca8dc990bcc50b8

Contents?: true

Size: 1.8 KB

Versions: 9

Compression:

Stored size: 1.8 KB

Contents

module Mondrian
  module OLAP
    module CellSet
      module Ruby
        extend ActiveSupport::Concern

        def to_ruby
          cell_set = ::CellSet::CellSet.new
          axes = getAxes.map do |axis|
            ::CellSet::CellSetAxis.new(:axis_ordinal => axis.getAxisOrdinal.axisOrdinal, :cell_set => cell_set, :positions => buildPositions(axis))
          end
          cell_set.axes = axes
          cell_set.send("cellHash=", getCellHash)
          cell_set.freeze
          cell_set
        end

        private
        def buildPositions(axis)
          axis.positions.map do |position|
            members = position.getMembers.map do |member|
              ::CellSet::Member.new(
                :caption => member.getCaption,
                :depth => member.getDepth,
                :description => member.getDescription,
                :memberType => member.getMemberType.to_s,
                :name => member.getName,
                :ordinal => member.getOrdinal,
                :uniqueName => member.getUniqueName
              )
            end
            ::CellSet::Position.new(:members => members, :ordinal => position.getOrdinal)
          end
        end

        def getCellHash
          cells = {}
          maxOrdinal.times do |i|
            formatted_value, value = *getCell(i).try{|cell| [cell.getFormattedValue, cell.getValue]}
            unless formatted_value.blank? && value.nil?
              # Build key as string
              cells[i.to_s] = {
                "formatted_value" => formatted_value,
                "value" => value
              }
            end
          end
          cells
        end

        def maxOrdinal
          modulo = 1
          getAxes.each do |axis|
            modulo *= axis.getPositionCount
          end
          modulo
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cell_set-0.2.3 lib/mondrian/olap/cell_set/ruby.rb
cell_set-0.2.2 lib/mondrian/olap/cell_set/ruby.rb
cell_set-0.2.1 lib/mondrian/olap/cell_set/ruby.rb
cell_set-0.2.0 lib/mondrian/olap/cell_set/ruby.rb
cell_set-0.1.4 lib/mondrian/olap/cell_set/ruby.rb
cell_set-0.1.3 lib/mondrian/olap/cell_set/ruby.rb
cell_set-0.1.2 lib/mondrian/olap/cell_set/ruby.rb
cell_set-0.1.1 lib/mondrian/olap/cell_set/ruby.rb
cell_set-0.1.0 lib/mondrian/olap/cell_set/ruby.rb