lib/gooddata/models/metric.rb in gooddata-0.6.0.pre11 vs lib/gooddata/models/metric.rb in gooddata-0.6.0
- old
+ new
@@ -1,19 +1,20 @@
-require File.join(File.dirname(__FILE__), "metadata")
-require File.join(File.dirname(__FILE__), '../goodzilla/goodzilla')
+# encoding: UTF-8
+require_relative 'metadata'
+require_relative '../goodzilla/goodzilla'
+
module GoodData
# Metric representation
class Metric < GoodData::MdObject
-
root_key :metric
class << self
def [](id)
if id == :all
GoodData.get(GoodData.project.md['query'] + '/metrics/')['query']['entries']
- else
+ else
super
end
end
def xcreate(options)
@@ -30,71 +31,69 @@
extended_notation = false
title = nil
else
title = options[:title]
summary = options[:summary]
- expression = options[:expression] || fail("Metric has to have its expression defined")
+ expression = options[:expression] || fail('Metric has to have its expression defined')
extended_notation = options[:extended_notation] || false
end
expression = if extended_notation
- dict = {
- :facts => GoodData::Fact[:all].reduce({}) {|memo, item| memo[item["title"]] = item["link"]; memo},
- :attributes => GoodData::Attribute[:all].reduce({}) {|memo, item| memo[item["title"]] = item["link"]; memo},
- :metrics => GoodData::Metric[:all].reduce({}) {|memo, item| memo[item["title"]] = item["link"]; memo},
- }
- interpolated_metric = GoodData::SmallGoodZilla.interpolate_metric(expression, dict)
- interpolated_metric
- else
- expression
- end
+ dict = {
+ :facts => GoodData::Fact[:all].reduce({}) { |memo, item| memo[item['title']] = item['link']; memo },
+ :attributes => GoodData::Attribute[:all].reduce({}) { |memo, item| memo[item['title']] = item['link']; memo },
+ :metrics => GoodData::Metric[:all].reduce({}) { |memo, item| memo[item['title']] = item['link']; memo },
+ }
+ interpolated_metric = GoodData::SmallGoodZilla.interpolate_metric(expression, dict)
+ interpolated_metric
+ else
+ expression
+ end
Metric.new({
- "metric" => {
- "content" => {
- "format" => "#,##0",
- "expression" => expression
- },
- "meta" => {
- "tags" => "",
- "summary" => summary,
- "title" => title,
- }
- }
- })
+ 'metric' => {
+ 'content' => {
+ 'format' => '#,##0',
+ 'expression' => expression
+ },
+ 'meta' => {
+ 'tags' => '',
+ 'summary' => summary,
+ 'title' => title,
+ }
+ }
+ })
end
def execute(expression, options={})
m = if expression.is_a?(String)
- GoodData::Metric.create({:title => "Temporary metric to be deleted", :expression => expression}.merge(options))
- else
- GoodData::Metric.create({:title => "Temporary metric to be deleted"}.merge(expression))
- end
+ GoodData::Metric.create({:title => 'Temporary metric to be deleted', :expression => expression}.merge(options))
+ else
+ GoodData::Metric.create({:title => 'Temporary metric to be deleted'}.merge(expression))
+ end
m.execute
end
def xexecute(expression)
if expression.is_a?(String)
execute({:expression => expression, :extended_notation => true})
else
execute(expression.merge({:extended_notation => true}))
end
end
-
end
def execute
res = GoodData::ReportDefinition.execute(:left => self)
res[0][0]
end
def validate
- fail "Meric needs to have title" if title.nil?
+ fail 'Meric needs to have title' if title.nil?
true
end
def is_metric?
true
end
-
end
end