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).
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( = {}) an_attribute = [:attribute] a_type = [: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 = [: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 |