egg_carton 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ egg_carton (0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ ffi (1.0.11)
11
+ growl (1.0.3)
12
+ guard (0.10.0)
13
+ ffi (>= 0.5.0)
14
+ thor (~> 0.14.6)
15
+ guard-rspec (0.5.10)
16
+ guard (>= 0.8.4)
17
+ rake (0.9.2.2)
18
+ rb-fsevent (0.4.3.1)
19
+ rspec (2.8.0)
20
+ rspec-core (~> 2.8.0)
21
+ rspec-expectations (~> 2.8.0)
22
+ rspec-mocks (~> 2.8.0)
23
+ rspec-core (2.8.0)
24
+ rspec-expectations (2.8.0)
25
+ diff-lcs (~> 1.1.2)
26
+ rspec-mocks (2.8.0)
27
+ thor (0.14.6)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ egg_carton!
34
+ growl
35
+ guard-rspec
36
+ rake
37
+ rb-fsevent
38
+ rspec (~> 2.8)
@@ -0,0 +1,4 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/egg_carton/(.+)\.rb}) { |m| "spec/egg_carton/#{m[1]}_spec.rb" }
4
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Brandon Hilkert
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ Egg Carton Gem
2
+ =======================
3
+
4
+ Egg Carton is a series of Ruby number helpers to help with reporting conversions and click-throughs.
5
+
6
+ Don't put all your eggs in one basket...
7
+
8
+ Usage
9
+ -----
10
+
11
+ `gem install egg_carton`
12
+
13
+
14
+ Helpers
15
+ -------
16
+
17
+ The helper methods use a pre-calculate numberator and denominator with the goal of calculating an average or conversion.
18
+ In many cases, counts are pulled from a database and then need to be displayed properly for reporting. These methods help with
19
+ the display portion once the values have been calculated.
20
+
21
+ In Rails, helper methods are added to `ActionView::Base`, and as a result, available to views.
22
+
23
+ __Average Method__
24
+
25
+ `average(1, 4)`
26
+
27
+ `# => 0.25`
28
+
29
+ `average(1, 4, 1)`
30
+
31
+ `# => 0.3`
32
+
33
+ __Conversion Method__
34
+
35
+ `conversion(1, 4, 2)`
36
+
37
+ `# => "25%"`
38
+
39
+ `conversion(1, 4, 2, :percentage => false)`
40
+
41
+ `# => 0.25`
42
+
43
+ `conversion(1, 4, 1)`
44
+
45
+ `# => "30%"`
46
+
47
+ `conversion(1, 4, 1, :percentage => false)`
48
+
49
+ `# => 0.3`
50
+
51
+ Released under the [MIT license](http://www.opensource.org/licenses/mit-license.php).
52
+
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :test => :spec
10
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "egg_carton/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "egg_carton"
7
+ s.version = EggCarton::VERSION
8
+ s.authors = ["Brandon Hilkert"]
9
+ s.email = ["brandonhilkert@gmail.com"]
10
+ s.homepage = "https://github.com/brandonhilkert/egg_carton"
11
+ s.summary = %q{Egg Carton Format Helpers}
12
+ s.description = %q{Egg Carton is a series of Ruby number helpers to help with reporting conversions and click-throughs.}
13
+
14
+ s.rubyforge_project = "egg_carton"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec", "~> 2.8"
22
+ s.add_development_dependency "guard-rspec"
23
+ s.add_development_dependency "growl"
24
+ s.add_development_dependency "rake"
25
+ if RUBY_PLATFORM =~ /darwin/i
26
+ s.add_development_dependency 'rb-fsevent'
27
+ s.add_development_dependency 'growl'
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ require "egg_carton/version"
2
+ require "egg_carton/helper"
3
+ require "egg_carton/railtie" if defined?(Rails)
4
+
5
+ module EggCarton
6
+ end
@@ -0,0 +1,60 @@
1
+ module EggCarton
2
+
3
+ module Helper
4
+
5
+ # Public: Calculates average for a numerator and denominator.
6
+ #
7
+ # numberator - The Integer or Float to use as the numberator.
8
+ # denominator - The Integer or Float to use as the denominator.
9
+ # precision - The Integer or decimal places to preserve.
10
+ #
11
+ # Examples
12
+ #
13
+ # average(1, 4, 2)
14
+ # # => 0.25
15
+ #
16
+ # average(1, 4, 1)
17
+ # # => 0.3
18
+ #
19
+ # Returns the Float result of the calculation
20
+ def average(numerator, denominator, precision = 0)
21
+ return 0 if denominator.zero?
22
+ (numerator.to_f / denominator.to_f).round(precision)
23
+ end
24
+
25
+ # Public: Calculates conversion for a numerator and denominator.
26
+ #
27
+ # numberator - The Integer or Float to use as the numberator.
28
+ # denominator - The Integer or Float to use as the denominator.
29
+ # precision - The Integer or decimal places to preserve.
30
+ # opts - The options Hash
31
+ #
32
+ # Examples
33
+ #
34
+ # conversion(1, 4, 2)
35
+ # # => "25%"
36
+ #
37
+ # conversion(1, 4, 2, :percentage => false)
38
+ # # => "0.25"
39
+ #
40
+ # conversion(1, 4, 1)
41
+ # # => "30%"
42
+ #
43
+ # conversion(1, 4, 1, :percentage => false)
44
+ # # => "0.3"
45
+ #
46
+ # Returns the Float result of the calculation
47
+ def conversion(numerator, denominator, precision = 0, opts={})
48
+ return 0 if denominator.zero?
49
+ as_percentage = opts[:percentage].nil? ? true : opts[:percentage]
50
+
51
+ if as_percentage
52
+ result = (numerator.to_f / denominator.to_f * 100).round(precision)
53
+ "#{result}%"
54
+ else
55
+ result = (numerator.to_f / denominator.to_f).round(precision)
56
+ "#{result}"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,9 @@
1
+ require "rails"
2
+
3
+ module EggCarton
4
+ class Railtie < Rails::Railtie
5
+ initializer "egg_carton.helper" do
6
+ ActionView::Base.send :include, Helper
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module EggCarton
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ class Test
4
+ include EggCarton::Helper
5
+ end
6
+
7
+ module EggCarton
8
+
9
+ describe "Helper" do
10
+ let(:test) { Test.new }
11
+
12
+ describe "#average" do
13
+ it "should return 4" do
14
+ test.average(40, 10).should == 4
15
+ end
16
+
17
+ it "should return 4.0" do
18
+ test.average(40, 10, 1).should == 4.0
19
+ end
20
+
21
+ it "should return 0 if denominator is 0" do
22
+ test.average(10, 0).should == 0
23
+ end
24
+ end
25
+
26
+ describe "#conversion" do
27
+ it "should return 20%" do
28
+ test.conversion(2, 4).should == "50%"
29
+ end
30
+
31
+ it "should return 20.0%" do
32
+ test.conversion(2, 4, 1).should == "50.0%"
33
+ end
34
+
35
+ it "should return 0 if denominator is 0" do
36
+ test.conversion(10, 0).should == 0
37
+ end
38
+
39
+ it "should not calculate percentage" do
40
+ test.conversion(2, 4, 4, :percentage => false).should_not include("%")
41
+ end
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'egg_carton'
5
+
6
+ RSpec.configure do |config|
7
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: egg_carton
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brandon Hilkert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-17 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70318430644820 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.8'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70318430644820
25
+ - !ruby/object:Gem::Dependency
26
+ name: guard-rspec
27
+ requirement: &70318430674600 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70318430674600
36
+ - !ruby/object:Gem::Dependency
37
+ name: growl
38
+ requirement: &70318430674140 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70318430674140
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70318430673720 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70318430673720
58
+ - !ruby/object:Gem::Dependency
59
+ name: rb-fsevent
60
+ requirement: &70318430673260 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70318430673260
69
+ - !ruby/object:Gem::Dependency
70
+ name: growl
71
+ requirement: &70318430672840 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70318430672840
80
+ description: Egg Carton is a series of Ruby number helpers to help with reporting
81
+ conversions and click-throughs.
82
+ email:
83
+ - brandonhilkert@gmail.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - .rspec
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - Guardfile
92
+ - LICENSE
93
+ - README.md
94
+ - Rakefile
95
+ - egg_carton.gemspec
96
+ - lib/egg_carton.rb
97
+ - lib/egg_carton/helper.rb
98
+ - lib/egg_carton/railtie.rb
99
+ - lib/egg_carton/version.rb
100
+ - spec/egg_carton/helper_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: https://github.com/brandonhilkert/egg_carton
103
+ licenses: []
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project: egg_carton
122
+ rubygems_version: 1.8.10
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Egg Carton Format Helpers
126
+ test_files:
127
+ - spec/egg_carton/helper_spec.rb
128
+ - spec/spec_helper.rb