geckoboard 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 407eb2ffdfdf941725c19f6b00912f94470d07f6
4
+ data.tar.gz: df0c2e6cbdaea03cc960367394aa376aa655b46c
5
+ SHA512:
6
+ metadata.gz: 7cbadef33776673b86e8a45e853179567ba38393cfe7043f36d5d641692c269e31a9d972cf091b1b591052a3d932b5cdc3ce56edaebd2ac2e5d68a530d72b853
7
+ data.tar.gz: fb935f56c079706828e53b157d59f7bb186569623d13bf449e03c12ce2a196a80821d7399bed8c9613257e606778d925821acae8caf8e22e4111a3f1b81774e1
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --backtrace
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # Geckoboard
2
+
3
+ A little gem to expose data nicely to [Geckoboard](http://www.geckoboard.com/).
4
+
5
+ ## Install
6
+
7
+ Install with Rubygems:
8
+
9
+ gem install geckoboard
10
+
11
+ If you use bundler, add it to your Gemfile:
12
+
13
+ gem 'geckoboard'
14
+
15
+ ## Usage
16
+
17
+ ### List item
18
+
19
+ ```ruby
20
+ Geckoboard.list_item('text', 'description')
21
+ ```
22
+
23
+ ### Trendline
24
+
25
+ ```ruby
26
+ Geckoboard.trendline(
27
+ 'Text',
28
+ 10, # value
29
+ [1,2,4,7,10] # trendline values
30
+ )
31
+ ```
32
+
33
+ ### Comparison
34
+
35
+ ```ruby
36
+ Geckoboard.comparison(10, 20) # first and second value to compare
37
+ ```
38
+
39
+ ### Rag
40
+
41
+ ```ruby
42
+ Geckoboard.rag(
43
+ Geckoboard.gecko_item('Red', 10),
44
+ Geckoboard.gecko_item('Amber', 20),
45
+ Geckoboard.gecko_item('Green', 30),
46
+ )
47
+ ```
48
+
49
+ ### Geck-o-Meter
50
+
51
+ ```ruby
52
+ Geckoboard.geck_o_meter(
53
+ 80,
54
+ Geckoboard.gecko_item('Max value', 100),
55
+ Geckoboard.gecko_item('Min value', 0)
56
+ )
57
+ ```
58
+
59
+ ### Pie
60
+
61
+ ```ruby
62
+ Geckoboard.pie([
63
+ Geckoboard.pie_item(70, '70 percents label', 'FFFF10AA'),
64
+ Geckoboard.pie_item(30, '30 percents label', 'FFAA0AAA')
65
+ ])
66
+ ```
67
+
68
+ ### Helper Methods
69
+
70
+ #### Gecko Item
71
+ ```ruby
72
+ other_attributes = { label: 'label', type: 0 }
73
+ Geckoboard.gecko_item('text', 'value', other_attributes) # other_attributes are optional
74
+ ```
75
+
76
+ #### Pie Item
77
+ ```ruby
78
+ Geckoboard.pie_item('value', 'label', 'FFFF10') # color is optional
79
+ ```
80
+
81
+ ## License
82
+
83
+ MIT License
84
+
85
+ Copyright (C) 2014 by Nayeem Syed
86
+
87
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
88
+
89
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
90
+
91
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.pattern = "spec/*_spec.rb"
5
+ end
6
+
7
+ task :default => :test
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'geckoboard/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "geckoboard"
8
+ spec.version = Geckoboard::VERSION
9
+ spec.authors = ["Nayeem Syed"]
10
+ spec.email = ["developerinlondon@gmail.com"]
11
+ spec.summary = %q{Add update_or_create and delete_then_create to ActiveRecord models}
12
+ spec.homepage = "https://github.com/developerinlondon/geckoboard"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake", "~> 10.3", ">= 10.3.2"
22
+ spec.add_development_dependency "rspec", "~> 3.0", ">= 3.0.0"
23
+ spec.add_development_dependency "pry", "~> 0.9", ">= 0.9.12.6"
24
+ end
@@ -0,0 +1,3 @@
1
+ class Geckoboard
2
+ VERSION = "0.0.1"
3
+ end
data/lib/geckoboard.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'geckoboard/version'
2
+ require 'digest/md5'
3
+ require 'json'
4
+
5
+ class Geckoboard
6
+ def self.gecko_item(text, value, other_attributes = {})
7
+ { text: text, value: value }.
8
+ merge(other_attributes).
9
+ reject { |_, attribute_value| attribute_value.nil? }
10
+ end
11
+
12
+ def self.trendline(text, value, trendline, gecko_item_attributes = {})
13
+ widget item: [
14
+ gecko_item(text, value, gecko_item_attributes),
15
+ trendline
16
+ ]
17
+ end
18
+
19
+ def self.comparison(first, second)
20
+ widget item: [
21
+ gecko_item('', first),
22
+ gecko_item('', second)
23
+ ]
24
+ end
25
+
26
+ def self.list_item text, description, other_attributes = {}
27
+ widget other_attributes.merge({title: { text: text }, description: description})
28
+ end
29
+
30
+ def self.rag(red, amber, green)
31
+ widget item: [red, amber, green]
32
+ end
33
+
34
+ def self.pie pie_items
35
+ widget item: pie_items
36
+ end
37
+
38
+ def self.pie_item(value, label, color = nil)
39
+ gecko_item(nil, value, { label: label, color: color })
40
+ end
41
+
42
+ def self.geck_o_meter(value, max, min)
43
+ widget item: value, max: max, min: min
44
+ end
45
+
46
+ protected
47
+
48
+ def self.widget(widget)
49
+ widget.to_json
50
+ end
51
+ end
@@ -0,0 +1,173 @@
1
+ require 'spec_helper'
2
+
3
+ describe Geckoboard do
4
+ it 'should contain VERSION' do
5
+ expect(Geckoboard::VERSION).not_to eq be_nil
6
+ end
7
+
8
+ describe '.gecko_item' do
9
+ context 'with all arguments' do
10
+ let(:text) { 'text' }
11
+ let(:value) { 2 }
12
+ let(:attributes) { { label: 0 } }
13
+ let(:gecko_item) { Geckoboard.gecko_item(text, value, attributes) }
14
+
15
+ it 'should have text' do
16
+ expect(gecko_item[:text]).to eq text
17
+ end
18
+
19
+ it 'should have value' do
20
+ expect(gecko_item[:value]).to eq value
21
+ end
22
+
23
+ it 'should have label' do
24
+ expect(gecko_item[:label]).to eq attributes[:label]
25
+ end
26
+ end
27
+
28
+ context 'with empty arguments' do
29
+ let(:text) { nil }
30
+ let(:value) { nil }
31
+ let(:attributes) { { label: 0 } }
32
+ let(:gecko_item) { Geckoboard.gecko_item(text, value, attributes) }
33
+
34
+ it 'should not have text' do
35
+ expect(gecko_item[:text]).to eq text
36
+ end
37
+
38
+ it 'should not have value' do
39
+ expect(gecko_item[:value]).to eq value
40
+ end
41
+
42
+ it 'should have label' do
43
+ expect(gecko_item[:label]).to eq attributes[:label]
44
+ end
45
+ end
46
+ end
47
+
48
+
49
+ describe '.trendline' do
50
+ context 'with arguments' do
51
+ let(:text) { 'text' }
52
+ let(:value) { 2 }
53
+ let(:trendline_array) { [1, 2] }
54
+ let(:trendline) { Geckoboard.trendline(text, value, trendline_array) }
55
+ let(:parsed_trendline) { JSON.parse(trendline) }
56
+
57
+ it 'should have text' do
58
+ expect(parsed_trendline['item'].first['text']).to eq text
59
+ end
60
+
61
+ it 'should have value' do
62
+ expect(parsed_trendline['item'].first['value']).to eq value
63
+ end
64
+
65
+ it 'should have trendline array' do
66
+ expect(parsed_trendline['item'].last).to eq trendline_array
67
+ end
68
+ end
69
+ end
70
+
71
+ describe '.comparison' do
72
+ context 'with arguments' do
73
+ let(:first) { 1 }
74
+ let(:second) { 2 }
75
+ let(:comparison) { Geckoboard.comparison(first, second) }
76
+ let(:parsed_comparison) { JSON.parse(comparison) }
77
+
78
+ it 'should have first value' do
79
+ expect(parsed_comparison['item'].first['value']).to eq first
80
+ end
81
+
82
+ it 'should have second value' do
83
+ expect(parsed_comparison['item'][1]['value']).to eq second
84
+ end
85
+ end
86
+ end
87
+
88
+ describe '.list_item' do
89
+ context 'with arguments' do
90
+ let(:text) { 'text' }
91
+ let(:description) { 'description' }
92
+ let(:list_item) { Geckoboard.list_item(text, description) }
93
+ let(:parsed_list_item) { JSON.parse(list_item) }
94
+
95
+ it 'should have text' do
96
+ expect(parsed_list_item['title']['text']).to eq text
97
+ end
98
+
99
+ it 'should have description' do
100
+ expect(parsed_list_item['description']).to eq description
101
+ end
102
+ end
103
+ end
104
+
105
+ describe '.rag' do
106
+ context 'with arguments' do
107
+ let(:red) { 1 }
108
+ let(:amber) { 2 }
109
+ let(:green) { 3 }
110
+ let(:rag) { Geckoboard.rag(red, amber, green) }
111
+ let(:parsed_rag) { JSON.parse(rag) }
112
+
113
+ it 'should have items' do
114
+ expect(parsed_rag['item']).to eq [red, amber, green]
115
+ end
116
+ end
117
+ end
118
+
119
+ describe '.pie' do
120
+ context 'with argument' do
121
+ let(:pie_items) { [1, 2, 3] }
122
+ let(:pie) { Geckoboard.pie(pie_items) }
123
+ let(:parsed_pie) { JSON.parse(pie) }
124
+
125
+ it 'should have pie item' do
126
+ expect(parsed_pie['item']).to eq pie_items
127
+ end
128
+ end
129
+ end
130
+
131
+ describe '.pie_item' do
132
+ context 'with argument' do
133
+ let(:value) { 10 }
134
+ let(:label) { 'label' }
135
+ let(:color) { '#ffffff' }
136
+ let(:pie_item) { Geckoboard.pie_item(value, label, color) }
137
+
138
+ it 'should have value' do
139
+ expect(pie_item[:value]).to eq value
140
+ end
141
+
142
+ it 'should have label' do
143
+ expect(pie_item[:label]).to eq label
144
+ end
145
+
146
+ it 'should have color' do
147
+ expect(pie_item[:color]).to eq color
148
+ end
149
+ end
150
+ end
151
+
152
+ describe '.geck_o_meter' do
153
+ context 'with all arguments' do
154
+ let(:value) { 'value' }
155
+ let(:max) { 2 }
156
+ let(:min) { 1 }
157
+ let(:geck_o_meter) { Geckoboard.geck_o_meter(value, max, min) }
158
+ let(:parsed_geck_o_meter) { JSON.parse(geck_o_meter) }
159
+
160
+ it 'should have value' do
161
+ expect(parsed_geck_o_meter['item']).to eq value
162
+ end
163
+
164
+ it 'should have max' do
165
+ expect(parsed_geck_o_meter['max']).to eq max
166
+ end
167
+
168
+ it 'should have min' do
169
+ expect(parsed_geck_o_meter['min']).to eq min
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,8 @@
1
+ require 'geckoboard'
2
+ require 'pry'
3
+
4
+ RSpec.configure do |config|
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ config.order = 'random'
8
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geckoboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nayeem Syed
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 10.3.2
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '10.3'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 10.3.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 3.0.0
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '3.0'
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 3.0.0
67
+ - !ruby/object:Gem::Dependency
68
+ name: pry
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '0.9'
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 0.9.12.6
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0.9'
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 0.9.12.6
87
+ description:
88
+ email:
89
+ - developerinlondon@gmail.com
90
+ executables: []
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".gitignore"
95
+ - ".rspec"
96
+ - Gemfile
97
+ - README.md
98
+ - Rakefile
99
+ - geckoboard.gemspec
100
+ - lib/geckoboard.rb
101
+ - lib/geckoboard/version.rb
102
+ - spec/lib/geckoboard_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: https://github.com/developerinlondon/geckoboard
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.0
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Add update_or_create and delete_then_create to ActiveRecord models
128
+ test_files:
129
+ - spec/lib/geckoboard_spec.rb
130
+ - spec/spec_helper.rb
131
+ has_rdoc: