Sha256: 1bcd567fc46f0c2de6dc1720c9299a2bc2049c83c0bfbebfecb8bc892dc60f31

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

module GoodData::SmallGoodZilla
  
  def self.get_facts(a_maql_string)
    a_maql_string.scan(/#\"([^\"]+)\"/).flatten
  end

  def self.get_attributes(a_maql_string)
    a_maql_string.scan(/@\"([^\"]+)\"/).flatten
  end

  def self.get_metrics(a_maql_string)
    a_maql_string.scan(/\?"([^\"]+)\"/).flatten
  end

  def self.interpolate(values, dictionaries)
    {
      :facts => interpolate_values(values[:facts], dictionaries[:facts]),
      :attributes => interpolate_values(values[:attributes], dictionaries[:attributes]),
      :metrics => interpolate_values(values[:metrics], dictionaries[:metrics])
    }
  end

  def self.interpolate_values(keys, values)
    x = values.values_at(*keys)
    keys.zip(x)
  end

  def self.interpolate_metric(metric, dictionary)
    interpolated = interpolate({
      :facts => GoodData::SmallGoodZilla.get_facts(metric),
      :attributes => GoodData::SmallGoodZilla.get_attributes(metric),
      :metrics => GoodData::SmallGoodZilla.get_metrics(metric)
    }, dictionary)
    metric = interpolated[:facts].reduce(metric) {|memo, item| memo.sub("#\"#{item[0]}\"", "[#{item[1]}]")}
    metric = interpolated[:attributes].reduce(metric) {|memo, item| memo.sub("@\"#{item[0]}\"", "[#{item[1]}]")}
    metric = interpolated[:metrics].reduce(metric) {|memo, item| memo.sub("?\"#{item[0]}\"", "[#{item[1]}]")}
    metric
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gooddata-0.6.0.pre7 lib/gooddata/goodzilla/goodzilla.rb
gooddata-0.6.0.pre6 lib/gooddata/goodzilla/goodzilla.rb
gooddata-0.6.0.pre5 lib/gooddata/goodzilla/goodzilla.rb
gooddata-0.6.0.pre4 lib/gooddata/goodzilla/goodzilla.rb
gooddata-0.6.0.pre3 lib/gooddata/goodzilla/goodzilla.rb
gooddata-0.6.0.pre2 lib/gooddata/goodzilla/goodzilla.rb