Sha256: b5ed4c1c3a71fef0926013c0545f2a1bcc6dbe9bb769a27abed30ae76f345678

Contents?: true

Size: 922 Bytes

Versions: 7

Compression:

Stored size: 922 Bytes

Contents

module Mondrian::REST::Formatters
  module JSONRecords
    def self.call(result, env)
      qh = env['rack.request.query_hash']
      add_parents = qh['parents'] == 'true'
      debug = qh['debug'] == 'true'
      properties = qh['properties'] || []
      format = qh['format'] == 'array' ? 'array' : 'object'

      rows = Mondrian::REST::Formatters.tidy(result,
                                             add_parents: add_parents,
                                             debug: debug,
                                             properties: properties).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

7 entries across 7 versions & 1 rubygems

Version Path
mondrian-rest-0.7.6-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-0.7.5-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-0.7.4-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-0.7.3-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-0.7.2-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-0.7.1-java lib/mondrian_rest/formatters/jsonrecords.rb
mondrian-rest-0.7.0-java lib/mondrian_rest/formatters/jsonrecords.rb