slate 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,13 +8,33 @@ module Slate
8
8
  end
9
9
 
10
10
  def result
11
- nil # Override this
11
+ targets.map do |target|
12
+ name = target.first
13
+ points = target.last
14
+ target name, map(points)
15
+ end
12
16
  end
13
17
 
14
18
  protected
15
19
 
20
+ # This is the method to do calculations in children classes
21
+ def map(points)
22
+ points
23
+ end
24
+
25
+ def targets
26
+ data.map { |t| [t["target"], t["datapoints"].map(&:first).compact] }
27
+ end
28
+
29
+ def target(name, value)
30
+ {
31
+ "name" => name,
32
+ "value" => value
33
+ }
34
+ end
35
+
16
36
  def data
17
- @data ||= JSON.parse(@graph.download(:json)).first["datapoints"].map(&:first).compact
37
+ @data ||= JSON.parse(@graph.download(:json))
18
38
  end
19
39
  end
20
40
  end
@@ -1,8 +1,10 @@
1
1
  module Slate
2
2
  module Calculation
3
3
  class Last < Base
4
- def result
5
- data.last
4
+ protected
5
+
6
+ def map(points)
7
+ points.last
6
8
  end
7
9
  end
8
10
  end
@@ -1,8 +1,10 @@
1
1
  module Slate
2
2
  module Calculation
3
3
  class Mean < Base
4
- def result
5
- data.inject(0.0, :+) / data.size.to_f
4
+ protected
5
+
6
+ def map(points)
7
+ points.inject(0.0, :+) / points.size.to_f
6
8
  end
7
9
  end
8
10
  end
@@ -1,3 +1,3 @@
1
1
  module Slate
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -19,6 +19,6 @@ describe Slate::Calculation::Last do
19
19
 
20
20
  it "should calculate the mean of the series" do
21
21
  calculation = Slate::Calculation::Last.new(@graph)
22
- calculation.result.should == 3.0
22
+ calculation.result.should == [{ "name" => "some.stat", "value" => 3.0 }]
23
23
  end
24
24
  end
@@ -19,6 +19,6 @@ describe Slate::Calculation::Mean do
19
19
 
20
20
  it "should calculate the mean of the series" do
21
21
  calculation = Slate::Calculation::Mean.new(@graph)
22
- calculation.result.should == 1.5
22
+ calculation.result.should == [{ "name" => "some.stat", "value" => 1.5 }]
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
12
+ date: 2013-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
@@ -168,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  segments:
170
170
  - 0
171
- hash: 3951322141183346689
171
+ hash: -1731051461027255620
172
172
  required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  none: false
174
174
  requirements:
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  version: '0'
178
178
  segments:
179
179
  - 0
180
- hash: 3951322141183346689
180
+ hash: -1731051461027255620
181
181
  requirements: []
182
182
  rubyforge_project:
183
183
  rubygems_version: 1.8.24