panic_board_data 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in panic_board_data.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Darren Cauthon
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # PanicBoardData
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'panic_board_data'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install panic_board_data
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ module PanicBoardData
2
+
3
+ class DataSequence
4
+ attr_accessor :data, :title, :refresh_every_n_seconds
5
+
6
+ def initialize(title)
7
+ @title = title
8
+ @data = {}
9
+ @refresh_every_n_seconds = 120
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,57 @@
1
+ # http://www.panic.com/statusboard/docs/graph_tutorial.pdf
2
+ module PanicBoardData
3
+
4
+ GRAPH_TYPES = [:bar, :line]
5
+ COLORS = [:yellow, :green, :red, :purple, :blue, :mediumGray, :pink, :aqua, :orange, :light_gray]
6
+
7
+ class Graph
8
+
9
+ attr_accessor :title, :color, :total, :type
10
+ attr_accessor :data_sequences
11
+
12
+ def initialize
13
+ @data_sequences = []
14
+ end
15
+
16
+ def to_hash
17
+ {
18
+ 'graph' => graph
19
+ }
20
+ end
21
+
22
+ private
23
+
24
+ def graph
25
+ the_graph = {
26
+ 'title' => title,
27
+ 'color' => formatted_color,
28
+ 'type' => type.to_s,
29
+ 'total' => total.to_s,
30
+ 'datasequences' => formatted_data_sequences
31
+ }
32
+ the_graph.delete('color') if the_graph['color'] == ''
33
+ the_graph
34
+ end
35
+
36
+ def formatted_data_sequences
37
+ data_sequences.map do |data_sequence|
38
+ {
39
+ 'title' => data_sequence.title,
40
+ 'refreshEveryNSeconds' => data_sequence.refresh_every_n_seconds,
41
+ 'datapoints' => data_points_for(data_sequence)
42
+ }
43
+ end
44
+ end
45
+
46
+ def data_points_for data_sequence
47
+ data_sequence.data.map do |k, v|
48
+ { 'title' => k, 'value' => v }
49
+ end
50
+ end
51
+
52
+ def formatted_color
53
+ color == :light_gray ? 'lightGray' : color.to_s
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,3 @@
1
+ module PanicBoardData
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,5 @@
1
+ Dir[File.dirname(__FILE__) + '/panic_board_data/*.rb'].each {|file| require file }
2
+
3
+ module PanicBoardData
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'panic_board_data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "panic_board_data"
8
+ spec.version = PanicBoardData::VERSION
9
+ spec.authors = ["Darren Cauthon"]
10
+ spec.email = ["darren@cauthon.com"]
11
+ spec.description = %q{Export data for Panic Board}
12
+ spec.summary = %q{Export data for Panic Board}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "json"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "subtle"
25
+ spec.add_development_dependency "mocha"
26
+ spec.add_development_dependency "contrast"
27
+ end
@@ -0,0 +1,199 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe PanicBoardData::Graph do
4
+ it "should exist" do
5
+ PanicBoardData::Graph.nil?.must_equal false
6
+ end
7
+
8
+ it "should default to an empty data_sequence array" do
9
+ PanicBoardData::Graph.new.data_sequences.count.must_equal 0
10
+ end
11
+
12
+ it "should have the accepted graph types" do
13
+ PanicBoardData::GRAPH_TYPES.must_equal [:bar, :line]
14
+ end
15
+
16
+ it "should have the accepted colors" do
17
+ PanicBoardData::COLORS.must_equal [:yellow, :green, :red, :purple, :blue, :mediumGray, :pink, :aqua, :orange, :light_gray]
18
+ end
19
+
20
+ describe "to_hash" do
21
+
22
+ let(:graph) { PanicBoardData::Graph.new }
23
+
24
+ describe "first example" do
25
+ before do
26
+ graph.title = "Soft Drink Sales"
27
+ graph.color = :red
28
+ graph.total = true
29
+ graph.type = :bar
30
+
31
+ data_sequence = PanicBoardData::DataSequence.new('X-Cola')
32
+ data_sequence.data['2008'] = 22
33
+ data_sequence.data['2009'] = 24
34
+ data_sequence.data['2010'] = 25.5
35
+ data_sequence.data['2011'] = 27.9
36
+ data_sequence.data['2012'] = 31
37
+
38
+ graph.data_sequences << data_sequence
39
+ @result = graph.to_hash
40
+ end
41
+
42
+ it "should set the title" do
43
+ @result['graph']['title'].must_equal 'Soft Drink Sales'
44
+ end
45
+
46
+ it "should set the color" do
47
+ @result['graph']['color'].must_equal 'red'
48
+ end
49
+
50
+ it "should set the total" do
51
+ @result['graph']['total'].must_equal 'true'
52
+ end
53
+
54
+ it "should set the type" do
55
+ @result['graph']['type'].must_equal 'bar'
56
+ end
57
+
58
+ it "should default to refreshing every 120 seconds" do
59
+ @result['graph']['datasequences'][0]['refreshEveryNSeconds'].must_equal 120
60
+ end
61
+
62
+ it "should add the data sequences" do
63
+ @result['graph']['datasequences'][0]['title'].must_equal "X-Cola"
64
+ @result['graph']['datasequences'][0]['datapoints'][0].must_equal( { 'title' => '2008', 'value' => 22 } )
65
+ @result['graph']['datasequences'][0]['datapoints'][1].must_equal( { 'title' => '2009', 'value' => 24 } )
66
+ @result['graph']['datasequences'][0]['datapoints'][2].must_equal( { 'title' => '2010', 'value' => 25.5 } )
67
+ @result['graph']['datasequences'][0]['datapoints'][3].must_equal( { 'title' => '2011', 'value' => 27.9 } )
68
+ @result['graph']['datasequences'][0]['datapoints'][4].must_equal( { 'title' => '2012', 'value' => 31 } )
69
+ end
70
+ end
71
+
72
+ describe "second example" do
73
+ before do
74
+ graph.title = "Another Example"
75
+ graph.color = :blue
76
+ graph.total = false
77
+ graph.type = :line
78
+
79
+ data_sequence = PanicBoardData::DataSequence.new('Apples')
80
+ data_sequence.refresh_every_n_seconds = 60
81
+ data_sequence.data['1908'] = 1
82
+ data_sequence.data['1909'] = 2
83
+ data_sequence.data['1910'] = 3
84
+ data_sequence.data['1911'] = 4
85
+ data_sequence.data['1912'] = 5
86
+
87
+ graph.data_sequences << data_sequence
88
+ @result = graph.to_hash
89
+ end
90
+
91
+ it "should set the title" do
92
+ @result['graph']['title'].must_equal 'Another Example'
93
+ end
94
+
95
+ it "should set the color" do
96
+ @result['graph']['color'].must_equal 'blue'
97
+ end
98
+
99
+ it "should set the total" do
100
+ @result['graph']['total'].must_equal 'false'
101
+ end
102
+
103
+ it "should set the type" do
104
+ @result['graph']['type'].must_equal 'line'
105
+ end
106
+
107
+ it "should set the refreshing every n seconds value" do
108
+ @result['graph']['datasequences'][0]['refreshEveryNSeconds'].must_equal 60
109
+ end
110
+
111
+ it "should add the data sequences" do
112
+ @result['graph']['datasequences'][0]['title'].must_equal "Apples"
113
+ @result['graph']['datasequences'][0]['datapoints'][0].must_equal( { 'title' => '1908', 'value' => 1 } )
114
+ @result['graph']['datasequences'][0]['datapoints'][1].must_equal( { 'title' => '1909', 'value' => 2 } )
115
+ @result['graph']['datasequences'][0]['datapoints'][2].must_equal( { 'title' => '1910', 'value' => 3 } )
116
+ @result['graph']['datasequences'][0]['datapoints'][3].must_equal( { 'title' => '1911', 'value' => 4 } )
117
+ @result['graph']['datasequences'][0]['datapoints'][4].must_equal( { 'title' => '1912', 'value' => 5 } )
118
+ end
119
+ end
120
+
121
+ describe "third example" do
122
+ before do
123
+ graph.title = "Third Example"
124
+ graph.color = :light_gray
125
+ graph.total = true
126
+ graph.type = :line
127
+
128
+ first = PanicBoardData::DataSequence.new('Apples')
129
+ first.refresh_every_n_seconds = 5
130
+ first.data['1908'] = 1
131
+ first.data['1909'] = 2
132
+ first.data['1910'] = 3
133
+ first.data['1911'] = 4
134
+ first.data['1912'] = 5
135
+
136
+ second = PanicBoardData::DataSequence.new('Oranges')
137
+ second.refresh_every_n_seconds = 10
138
+ second.data['2008'] = 6
139
+ second.data['2009'] = 7
140
+ second.data['2010'] = 8
141
+ second.data['2011'] = 9
142
+ second.data['2012'] = 10
143
+
144
+ graph.data_sequences << first
145
+ graph.data_sequences << second
146
+
147
+ @result = graph.to_hash
148
+ end
149
+
150
+ it "should set the title" do
151
+ @result['graph']['title'].must_equal 'Third Example'
152
+ end
153
+
154
+ it "should set the color" do
155
+ @result['graph']['color'].must_equal 'lightGray'
156
+ end
157
+
158
+ it "should set the total" do
159
+ @result['graph']['total'].must_equal 'true'
160
+ end
161
+
162
+ it "should set the type" do
163
+ @result['graph']['type'].must_equal 'line'
164
+ end
165
+
166
+ it "should add the data sequences" do
167
+ @result['graph']['datasequences'][0]['title'].must_equal "Apples"
168
+ @result['graph']['datasequences'][0]['datapoints'][0].must_equal( { 'title' => '1908', 'value' => 1 } )
169
+ @result['graph']['datasequences'][0]['datapoints'][1].must_equal( { 'title' => '1909', 'value' => 2 } )
170
+ @result['graph']['datasequences'][0]['datapoints'][2].must_equal( { 'title' => '1910', 'value' => 3 } )
171
+ @result['graph']['datasequences'][0]['datapoints'][3].must_equal( { 'title' => '1911', 'value' => 4 } )
172
+ @result['graph']['datasequences'][0]['datapoints'][4].must_equal( { 'title' => '1912', 'value' => 5 } )
173
+
174
+ @result['graph']['datasequences'][1]['title'].must_equal "Oranges"
175
+ @result['graph']['datasequences'][1]['datapoints'][0].must_equal( { 'title' => '2008', 'value' => 6 } )
176
+ @result['graph']['datasequences'][1]['datapoints'][1].must_equal( { 'title' => '2009', 'value' => 7 } )
177
+ @result['graph']['datasequences'][1]['datapoints'][2].must_equal( { 'title' => '2010', 'value' => 8 } )
178
+ @result['graph']['datasequences'][1]['datapoints'][3].must_equal( { 'title' => '2011', 'value' => 9 } )
179
+ @result['graph']['datasequences'][1]['datapoints'][4].must_equal( { 'title' => '2012', 'value' => 10 } )
180
+ end
181
+
182
+ it "should set the refreshing every n seconds value" do
183
+ @result['graph']['datasequences'][0]['refreshEveryNSeconds'].must_equal 5
184
+ @result['graph']['datasequences'][1]['refreshEveryNSeconds'].must_equal 10
185
+ end
186
+ end
187
+
188
+ describe "no color" do
189
+ before do
190
+ graph.title = "Soft Drink Sales"
191
+ @result = graph.to_hash
192
+ end
193
+
194
+ it "should set not set a color" do
195
+ @result['graph']['color'].nil?.must_equal true
196
+ end
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,7 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'minitest/pride'
4
+ require 'subtle'
5
+ require 'contrast'
6
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/panic_board_data')
7
+ require 'mocha/setup'
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: panic_board_data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Darren Cauthon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: subtle
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: mocha
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: contrast
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Export data for Panic Board
111
+ email:
112
+ - darren@cauthon.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - LICENSE.txt
120
+ - README.md
121
+ - Rakefile
122
+ - lib/panic_board_data.rb
123
+ - lib/panic_board_data/data_sequence.rb
124
+ - lib/panic_board_data/graph.rb
125
+ - lib/panic_board_data/version.rb
126
+ - panic_board_data.gemspec
127
+ - spec/panic_board_data/graph_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: ''
130
+ licenses:
131
+ - MIT
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ segments:
143
+ - 0
144
+ hash: 2655303414096831975
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ segments:
152
+ - 0
153
+ hash: 2655303414096831975
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 1.8.24
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: Export data for Panic Board
160
+ test_files:
161
+ - spec/panic_board_data/graph_spec.rb
162
+ - spec/spec_helper.rb