Method: GoodData::SmallGoodZilla.pretty_print

Defined in:
lib/gooddata/goodzilla/goodzilla.rb

.pretty_print(expression, opts = { client: GoodData.connection, project: GoodData.project }) ⇒ String

Pretty prints the MAQL expression. This basically means it finds out names of objects and elements and print their values instead of URIs

Parameters:

  • expression (String)

    Expression to be beautified

Returns:

  • (String)

    Pretty printed MAQL expression



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/gooddata/goodzilla/goodzilla.rb', line 94

def pretty_print(expression, opts = { client: GoodData.connection, project: GoodData.project })
  temp = expression.dup
  pairs = get_uris(expression).pmap do |uri|
    if uri =~ /elements/
      begin
        ['element', uri, Attribute.find_element_value(uri, opts)]
      rescue AttributeElementNotFound
        ['element', uri, '(empty value)']
      end
    else
      ['object', uri, GoodData::MdObject[uri, opts].title]
    end
  end
  pairs.sort_by! { |p| p[0] }
  pairs.each do |el|
    uri = el[1]
    obj = el[2]
    temp.gsub!(uri, obj)
  end
  temp
end