class ASTNode

Constants

DEFAULT_GRAPH_PROPERTIES
METRIC_PROC_FUNCTIONS

An array of proc functions to be applied on compile time, the first argument is the metric node and the second, the current string its result will be assigned to the compiled string

Attributes

children[RW]
graph_properties[RW]
parent[RW]
properties[RW]
root_node[RW]

Public Class Methods

new(raw_data) click to toggle source
# File lib/ast_node.rb, line 20
def initialize(raw_data)
  @root_node = nil
  @raw_data = raw_data
  @children = []
  @properties = {'graph_period' => "seconds","category" => "other"}
  @graph_properties = DEFAULT_GRAPH_PROPERTIES
  @graph_properties[:colorList] = default_colors
  @parent = nil
end

Public Instance Methods

add_child(child) click to toggle source

Add a child to the node

# File lib/ast_node.rb, line 43
def add_child(child)
  if self.root?
    child.root_node = self
  else
    child.root_node = self.root_node
  end

  child.parent = self
  children << child
end
children_of_class(klass) click to toggle source
# File lib/ast_node.rb, line 38
def children_of_class(klass)
  children.select { |i| i.is_a? klass }
end
compile() click to toggle source
# File lib/ast_node.rb, line 54
def compile
  # The compilation is done twice cause there are certain cases where is necessary, a better implementation would control whether this is needed
  # or not, but given the small impact I just do it twice
  children.map{|i| i.compile} if children
  children.map{|i| i.compile} if children
end
config=(config) click to toggle source
# File lib/ast_node.rb, line 30
def config=(config)
  self.properties.merge!(config)
end
default_colors() click to toggle source
# File lib/ast_node.rb, line 13
def default_colors
  %w(#00CC00 #0066B3 #FF8000 #FFCC00 #330099 #990099 #CCFF00 #FF0000 #808080
     #008F00 #00487D #B35A00 #B38F00         #6B006B #8FB300 #B30000 #BEBEBE
     #80FF80 #80C9FF #FFC080 #FFE680 #AA80FF #EE00CC #FF8080
     #666600 #FFBFFF #00FFCC #CC6699 #999900)
end
process_variables(properties) click to toggle source
# File lib/ast_node.rb, line 66
def process_variables(properties)
  [:vtitle,:title].each do |key|
    aux = properties[key]
    properties[key].scan(/\$\{(.*)\}/).each do 
      if self.properties.has_key? $1
        aux.gsub!(/\$\{#{$1}\}/,self.properties[$1])
      end
    end if properties[key]
    properties[key] = aux

  end
end
properties_to_url() click to toggle source

Returns the global properties as url values

# File lib/ast_node.rb, line 80
def properties_to_url
  
  # Color List initialization
  aux_graph_properties = self.graph_properties.clone
  process_variables(aux_graph_properties)
  aux_graph_properties[:colorList] = aux_graph_properties[:colorList].join(",") if aux_graph_properties[:colorList]

  # Change of the base stuff
  if  self.properties[:base]
    aux_graph_properties[:yMax] = aux_graph_properties[:yMax].to_f / self.properties[:base] 
    aux_graph_properties[:yMin] = aux_graph_properties[:yMin].to_f / self.properties[:base]
    aux_graph_properties.delete :yMax 
    aux_graph_properties.delete :yMin
  end

  aux = aux_graph_properties.map{|i,j| "#{i}=#{CGI.escape(j.to_s.gsub('%','percent'))}"}.join("&")
  return aux
end
root?() click to toggle source
# File lib/ast_node.rb, line 34
def root?
  @root_node == nil
end
targets() click to toggle source

Returns the FieldDeclaration Nodes

# File lib/ast_node.rb, line 62
def targets
  children_of_class(FieldDeclarationNode)
end
to_gdash() click to toggle source
# File lib/ast_node.rb, line 105
def to_gdash
  output = ""
  self.compile
  self.graph_properties.each do |k,v| 
    output += k.to_s + "\t\t" + '"' + v.to_s + '"' + "\n" unless k == :colorList || k == :yMin || k== :yMax
  end
  count = 0
  targets.each do |tg|
    metric_alias = tg.properties.delete(:alias)
    tg.children.delete_if { |i| i.class == LabelFieldPropertyNode}
    output += "field :#{tg.metric.split(".").last.to_sym},:alias => '#{metric_alias}', :data => \"#{tg.compile}\"\n"
    count += 1
  end
  return output
end
url() click to toggle source

This returns the url field of the graph after compiling it

# File lib/ast_node.rb, line 100
def url
  self.compile
  url = "#{properties[:endpoint]}/render/?width=586&height=308&#{properties_to_url}&target=" + CGI.escape(targets.map{|i| i.compile}.compact.join("&target="))
end