Sha256: 43cca3254b143c9c6a914b1450a21aea9fd243daf9cf13394009bb18d76a6218

Contents?: true

Size: 1.03 KB

Versions: 8

Compression:

Stored size: 1.03 KB

Contents

module Mondrian::REST::Formatters
  module JSONRecords
    def self.call(result, env)
      params = env['api.endpoint'].params
      add_parents = params['parents']
      debug = params['debug']
      sparse = params['sparse']
      properties = params['properties'] || []

      qh = env['rack.request.query_hash']
      format = qh['format'] == 'array' ? 'array' : 'object'

      rows = Mondrian::REST::Formatters.tidy(result,
                                             add_parents: add_parents,
                                             debug: debug,
                                             properties: properties,
                                             sparse: sparse).lazy
      keys = rows.first

      if format == 'array'
        {
          variables: keys,
          data: rows.drop(1).to_a
        }.to_json
      else
        {
          data: rows.with_index.with_object([]) { |(row, i), data|
            next if i == 0
            data << Hash[keys.zip(row)]
          }
        }.to_json
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mondrian-rest-1.0.4-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-1.0.3-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-1.0.2-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-1.0.1-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-1.0.0-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-0.7.9-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-0.7.8-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-0.7.7-java lib/mondrian_rest/formatters/jsonrecords.rb