Class: Cube::Evaluator
- Inherits:
-
Object
- Object
- Cube::Evaluator
- Defined in:
- lib/cube-evaluator.rb,
lib/cube-evaluator/version.rb
Constant Summary collapse
- VERSION =
"0.0.1"
Instance Method Summary collapse
-
#initialize(host = 'localhost', port = 1081) ⇒ Evaluator
constructor
A new instance of Evaluator.
- #metric(options = {}) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(host = 'localhost', port = 1081) ⇒ Evaluator
Returns a new instance of Evaluator.
6 7 8 |
# File 'lib/cube-evaluator.rb', line 6 def initialize(host = 'localhost', port = 1081) @url = "http://#{host}:#{port}/" end |
Instance Method Details
#metric(options = {}) ⇒ Object
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 |
# File 'lib/cube-evaluator.rb', line 14 def metric( = {}) uri = URI(@url) + "1.0/metric/get" params = .merge() do |k,v| if [DateTime, Date, Time].any?{ |klass| v.is_a?(klass) } v.to_time.utc.iso8601 elsif k == :step to_step(v) else v end end uri.query = URI.encode_www_form(params) res = Net::HTTP.get_response(uri) json_res = JSON.parse(res.body) json_res = json_res.map do |metric| metric.merge(metric) { |k, v| k == 'time' ? Time.parse(v) : v } end result = { :times => [], :values => [] } json_res.each do |metric| metric.each do |k,v| if k == 'time' result[:times] << v elsif k == 'value' result[:values] << v end end end result end |
#url ⇒ Object
10 11 12 |
# File 'lib/cube-evaluator.rb', line 10 def url @url || "" end |