Method: GoodData::Attribute#create_metric

Defined in:
lib/gooddata/models/metadata/attribute.rb

#create_metric(options = {}) ⇒ GoodData::Metric Also known as: create_measure

Creates the basic count metric with the attribute used. If you need to compute the attribute on a different dataset you can specify that in params. The metric created is not saved. express different dataset for performing the computation on. It basically serves for creating metrics like SELECT COUNT(User, Opportunity).

Parameters:

  • options (Hash) (defaults to: {})

    the options to pass to the value list

Options Hash (options):

  • :type (Symbol)

    type of aggregation function.

  • :attribute (Symbol)

    Use this attribute if you need to

Returns:



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/gooddata/models/metadata/attribute.rb', line 107

def create_metric(options = {})
  an_attribute = options[:attribute]
  a_type = options[:type] || :count
  unless ATTRIBUTE_BASE_AGGREGATIONS.include?(a_type)
    fail 'Suggested aggreagtion function (#{a_type}) does not exist for ' \
         'base metric created out of attribute. You can use only one of' \
         "#{ATTRIBUTE_BASE_AGGREGATIONS.map { |x| ':' + x.to_s }.join(',')}"
  end
  a_title = options[:title] || "#{a_type} of #{title}"
  if an_attribute
    project.create_metric("SELECT #{a_type.to_s.upcase}([#{uri}], [#{an_attribute.uri}])", title: a_title, extended_notation: false)
  else
    project.create_metric("SELECT #{a_type.to_s.upcase}([#{uri}])", title: a_title, extended_notation: false)
  end
end