metric_result.rb
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class Kalibro::MetricResult < Kalibro::Model
attr_accessor :id, :configuration, :value, :error
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
@errors = []
end
def id=(value)
@id = value.to_i
end
def configuration=(value)
@configuration = Kalibro::MetricConfigurationSnapshot.to_object value
end
def metric_configuration_snapshot
configuration
end
def error=(value)
@error = Kalibro::Throwable.to_object value
end
def descendant_results
self.class.request(:descendant_results_of, {:metric_result_id => self.id})[:descendant_result].to_a
end
def self.metric_results_of(module_result_id)
response = request(:metric_results_of, {:module_result_id => module_result_id})[:metric_result]
response = [] if response.nil?
response = [response] if response.is_a?(Hash)
response.map {|metric_result| new metric_result}
end
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]
response = [] if response.nil?
response = [response] if response.is_a?(Hash)
response.map {|date_metric_result| Kalibro::DateMetricResult.new date_metric_result}
end
end