class Expri::Dumper

Constants

NUMERICAL_ATTRIBUTES

Public Class Methods

new(options={}) click to toggle source
# File lib/expri/dumper.rb, line 3
def initialize(options={})
  @options = options
end

Public Instance Methods

run() click to toggle source
# File lib/expri/dumper.rb, line 7
def run
  str = ""
  str << header
  metrics = Metric.list
  metrics.each do |metric|
    metric = Metric.new(metric, {}, @options)
    metric.get
    str << dump_metric(metric)
  end
  str << footer
end

Private Instance Methods

dump_metric(metric) click to toggle source
# File lib/expri/dumper.rb, line 24
def dump_metric(metric)
  attributes = metric.attributes_without_defaults.dup

  type           = attributes.delete(:type)
  predicate      = attributes.delete(:predicate)

  # at bare minimum, window is required, so attributes size should always
  # be > 0 even after type and predicate are removed
  attributes_str = attributes.to_a.
    sort_by { |a| a[0] }.
    map { |a| "#{a[0]}: #{NUMERICAL_ATTRIBUTES.include?(a[0]) ? a[1] : %{"#{a[1]}"}}" }.
    join(",\n    ")

  # predicate is important, but optional
  str =  %{  metric "#{metric.name}",\n}
  str << %{    type: :#{type},\n}
  str << %{    predicate: #{predicate},\n} if predicate
  str << %{    #{attributes_str}\n\n}
end
header() click to toggle source
# File lib/expri/dumper.rb, line 48
def header
  "Expri.metrics(destroy_extras: false) do\n\n"
end