Class: KalibroGem::Entities::MetricResult

Inherits:
Model
  • Object
show all
Defined in:
lib/kalibro_gem/entities/metric_result.rb

Instance Attribute Summary collapse

Attributes inherited from Model

#kalibro_errors

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#==, create, create_array_from_hash, create_objects_array_from_hash, #destroy, #errors=, exists?, find, request, #save, #save!, #to_hash, to_object, to_objects_array

Methods included from RequestMethods::ClassMethods

#exists_action, #find_action, #id_params

Methods included from HashConverters

#convert_to_hash, #date_with_milliseconds, #field_to_hash

Methods included from XMLConverters

#get_xml, #xml_instance_class_name

Methods included from RequestMethods

#destroy_action, #destroy_params, #save_action, #save_params

Constructor Details

#initialize(attributes = {}) ⇒ MetricResult

Returns a new instance of MetricResult.



25
26
27
28
29
30
31
32
33
34
# File 'lib/kalibro_gem/entities/metric_result.rb', line 25

def initialize(attributes={})
  value = attributes[:value]
  @value = (value == "NaN") ? attributes[:aggregated_value].to_f : value.to_f
  attributes.each do |field, value|
    if field!= :value and field!= :aggregated_value and self.class.is_valid?(field)
      send("#{field}=", value)
    end
  end
  @kalibro_errors = []
end

Instance Attribute Details

#aggregated_valueObject

Returns the value of attribute aggregated_value.



23
24
25
# File 'lib/kalibro_gem/entities/metric_result.rb', line 23

def aggregated_value
  @aggregated_value
end

#configurationObject

Returns the value of attribute configuration.



23
24
25
# File 'lib/kalibro_gem/entities/metric_result.rb', line 23

def configuration
  @configuration
end

#idObject

Returns the value of attribute id.



23
24
25
# File 'lib/kalibro_gem/entities/metric_result.rb', line 23

def id
  @id
end

#valueObject

Returns the value of attribute value.



23
24
25
# File 'lib/kalibro_gem/entities/metric_result.rb', line 23

def value
  @value
end

Class Method Details

.history_of(metric_name, module_result_id) ⇒ Object



67
68
69
70
71
# File 'lib/kalibro_gem/entities/metric_result.rb', line 67

def self.history_of(metric_name, module_result_id)
  response = self.request(:history_of_metric, {:metric_name => metric_name,
                                               :module_result_id => module_result_id})[:date_metric_result]
  create_array_from_hash(response).map { |date_metric_result| KalibroGem::Entities::DateMetricResult.new date_metric_result }
end

.metric_results_of(module_result_id) ⇒ Object



63
64
65
# File 'lib/kalibro_gem/entities/metric_result.rb', line 63

def self.metric_results_of(module_result_id)
  create_objects_array_from_hash self.request(:metric_results_of, {:module_result_id => module_result_id})[:metric_result]
end

Instance Method Details

#descendant_resultsObject



56
57
58
59
60
61
# File 'lib/kalibro_gem/entities/metric_result.rb', line 56

def descendant_results
  response = self.class.request(:descendant_results_of, {:metric_result_id => id})[:descendant_result]
  response = [] if response.nil?
  response = [response] if response.is_a?(String)
  response.map {|descendant_result| descendant_result.to_f}
end

#metric_configuration_snapshotObject



44
45
46
# File 'lib/kalibro_gem/entities/metric_result.rb', line 44

def metric_configuration_snapshot
  @configuration
end