agery 1.0.0

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/.autotest ADDED
@@ -0,0 +1 @@
1
+ require "autotest/bundler"
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ coverage
4
+ Gemfile.lock
5
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --debug
3
+ --format nested
4
+ --profile
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rake"
6
+ gem "rspec"
7
+
8
+ platforms :mri_18 do
9
+ gem 'rcov'
10
+ gem 'ruby-debug'
11
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Chris Griego
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.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Agery
2
+
3
+ Agery is a set of extensions to Ruby's `Integer` class to assist developers
4
+ in generating arrays of ages. It's similar to ActiveSupport's extensions for
5
+ calculating bytes (`1.megabyte`) or durations (`3.days`). It's designed to
6
+ help generate data used when pricing is dependent upon age.
7
+
8
+ For example, a movie ticket may cost $13.99 for an adult, $4.99 for a young
9
+ child, $7.99 for a senior citizen, and free for infants. Also the movie may
10
+ be rated for mature audiences and not permit teenagers without an adult.
11
+
12
+ Since the primary use case is for pricing calculations, adults are treated as
13
+ an undefined age (`-1`) which would correspond to the most expensive price.
14
+ Also children default to `0` to ensure they will trigger the least expensive
15
+ price.
16
+
17
+ ## Examples
18
+
19
+ * `1.adult #=> [-1]`
20
+ * `3.teenagers #=> [13, 13, 13]`
21
+ * `2.infants #=> [0, 0]`
22
+ * `0.children #=> []`
23
+ * `2.seniors #=> [65, 65]`
24
+ * `2.adults + 1.child #=> [-1, -1, 0]`
25
+ * `1.over_21 #=> [21]`
26
+ * `2.under_18 #=> [17, 17]`
27
+
28
+ ## Customization
29
+
30
+ You can override Agery's concept of the age of an adult, infant, child,
31
+ teenager, and senior by overriding the Agery constant of the same name.
32
+
33
+ ## Installation
34
+
35
+ `gem install agery`
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'bundler/setup'
2
+ require 'rake/clean'
3
+ require 'rspec/core/rake_task'
4
+
5
+ Bundler::GemHelper.install_tasks
6
+ CLOBBER.include "pkg"
7
+
8
+ task :default => ['spec:rcov', :build]
9
+
10
+ RSpec::Core::RakeTask.new
11
+
12
+ namespace :spec do
13
+ desc "Run RSpec code examples with RCov"
14
+ RSpec::Core::RakeTask.new(:rcov) do |task|
15
+ task.rcov = true
16
+ task.rcov_opts = ["--failure-threshold 100", "--exclude spec/*,gems/*"]
17
+ end
18
+ end
data/agery.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "agery/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "agery"
7
+ s.version = Agery::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Chris Griego"]
10
+ s.email = ["cgriego@gmail.com"]
11
+ s.homepage = "https://github.com/cgriego/agery"
12
+ s.summary = %q{Integer extensions for generating arrays of ages.}
13
+ s.description = %q{Integer extensions for generating arrays of ages.}
14
+
15
+ s.rubyforge_project = "agery"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency "bundler"
23
+ end
@@ -0,0 +1,3 @@
1
+ module Agery
2
+ VERSION = "1.0.0"
3
+ end
data/lib/agery.rb ADDED
@@ -0,0 +1,55 @@
1
+ module Agery
2
+ ADULT = -1
3
+ INFANT = 0
4
+ CHILD = 0
5
+ TEENAGER = 13
6
+ SENIOR = 65
7
+
8
+ AGE_OVER = /^over_(0|[1-9]\d*)$/.freeze
9
+ AGE_UNDER = /^under_([1-9]\d*)$/.freeze
10
+
11
+ def adults
12
+ to_age_a ADULT
13
+ end
14
+ alias :adult :adults
15
+
16
+ def infants
17
+ to_age_a INFANT
18
+ end
19
+ alias :infant :infants
20
+
21
+ def children
22
+ to_age_a CHILD
23
+ end
24
+ alias :child :children
25
+
26
+ def teenagers
27
+ to_age_a TEENAGER
28
+ end
29
+ alias :teenager :teenagers
30
+
31
+ def seniors
32
+ to_age_a SENIOR
33
+ end
34
+ alias :senior :seniors
35
+
36
+ def respond_to?(method, *)
37
+ AGE_OVER === method.to_s || AGE_UNDER === method.to_s || super
38
+ end
39
+
40
+ def method_missing(method, *)
41
+ case method.to_s
42
+ when AGE_OVER then to_age_a($1.to_i)
43
+ when AGE_UNDER then to_age_a($1.to_i - 1)
44
+ else super
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def to_age_a(value=nil)
51
+ Array.new self, value
52
+ end
53
+ end
54
+
55
+ Integer.send :include, Agery
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ module Agery
4
+ describe "Agery::VERSION" do
5
+ subject { VERSION }
6
+
7
+ it { should be_a_kind_of String }
8
+
9
+ describe "is compliant with Semantic Versioning <http://semver.org/>" do
10
+ let(:gem_version) { Gem::Version.new VERSION }
11
+ subject { gem_version }
12
+
13
+ it { subject.should have(3).segments }
14
+
15
+ describe "major version" do
16
+ subject { gem_version.segments[0] }
17
+
18
+ it { should be_a_kind_of Fixnum }
19
+ end
20
+
21
+ describe "minor version" do
22
+ subject { gem_version.segments[1] }
23
+
24
+ it { should be_a_kind_of Fixnum }
25
+ end
26
+
27
+ describe "patch version" do
28
+ subject { gem_version.segments[2] }
29
+
30
+ it { subject.to_s.should =~ /\d+([A-Za-z][0-9A-Za-z-]*)?/ }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,209 @@
1
+ require 'spec_helper'
2
+
3
+ module Agery
4
+ describe "Agery::ADULT" do
5
+ it { ADULT.should == -1 }
6
+ end
7
+
8
+ describe "Agery::INFANT" do
9
+ it { INFANT.should == 0 }
10
+ end
11
+
12
+ describe "Agery::CHILD" do
13
+ it { CHILD.should == 0 }
14
+ end
15
+
16
+ describe "Agery::TEENAGER" do
17
+ it { TEENAGER.should == 13 }
18
+ end
19
+
20
+ describe "Agery::SENIOR" do
21
+ it { SENIOR.should == 65 }
22
+ end
23
+ end
24
+
25
+ describe "overriding the age constants" do
26
+ around do |example|
27
+ old_verbose, $VERBOSE = $VERBOSE, nil
28
+ eval "old_age, #{constant} = #{constant}, #{age}"
29
+ $VERBOSE = old_verbose
30
+
31
+ example.run
32
+
33
+ old_verbose, $VERBOSE = $VERBOSE, nil
34
+ eval "#{constant} = old_age"
35
+ $VERBOSE = old_verbose
36
+ end
37
+
38
+ context "ADULT = 21" do
39
+ let(:constant) { "Agery::ADULT" }
40
+ let(:age) { 21 }
41
+
42
+ describe 2 do
43
+ its(:adults) { should == [age, age] }
44
+ end
45
+ end
46
+
47
+ context "INFANT = -1" do
48
+ let(:constant) { "Agery::INFANT" }
49
+ let(:age) { -1 }
50
+
51
+ describe 2 do
52
+ its(:infants) { should == [age, age] }
53
+ end
54
+ end
55
+
56
+ context "CHILD = 2" do
57
+ let(:constant) { "Agery::CHILD" }
58
+ let(:age) { 2 }
59
+
60
+ describe 2 do
61
+ its(:children) { should == [age, age] }
62
+ end
63
+ end
64
+
65
+ context "TEENAGER = 16" do
66
+ let(:constant) { "Agery::TEENAGER" }
67
+ let(:age) { 16 }
68
+
69
+ describe 2 do
70
+ its(:teenagers) { should == [age, age] }
71
+ end
72
+ end
73
+
74
+ context "SENIOR = 75" do
75
+ let(:constant) { "Agery::SENIOR" }
76
+ let(:age) { 75 }
77
+
78
+ describe 2 do
79
+ its(:seniors) { should == [age, age] }
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "age extensions to Integer" do
85
+ describe 0 do
86
+ [
87
+ :adult, :adults,
88
+ :child, :children,
89
+ :infant, :infants,
90
+ :teenager, :teenagers,
91
+ :senior, :seniors,
92
+ :over_100, :under_100,
93
+ :over_1, :under_1
94
+ ].each do |method|
95
+ its(method) { should == [] }
96
+ it { should respond_to(method) }
97
+ end
98
+
99
+ it { should_not respond_to(:to_age_a) }
100
+
101
+ it "responds to public Integer methods" do
102
+ should respond_to(:to_i)
103
+ end
104
+
105
+ it "responds to private Integer methods" do
106
+ subject.respond_to?(:fork, true).should be_true
107
+ end
108
+ end
109
+
110
+ describe 1 do
111
+ its(:adult) { should == [-1] }
112
+ its(:adults) { should == [-1] }
113
+
114
+ its(:child) { should == [0] }
115
+ its(:children) { should == [0] }
116
+
117
+ its(:infant) { should == [0] }
118
+ its(:infants) { should == [0] }
119
+
120
+ its(:teenager) { should == [13] }
121
+ its(:teenagers) { should == [13] }
122
+
123
+ its(:senior) { should == [65] }
124
+ its(:seniors) { should == [65] }
125
+
126
+ its(:over_21) { should == [21] }
127
+ its(:over_65) { should == [65] }
128
+
129
+ its(:under_2) { should == [1] }
130
+ its(:under_10) { should == [9] }
131
+ its(:under_12) { should == [11] }
132
+ its(:under_17) { should == [16] }
133
+ its(:under_21) { should == [20] }
134
+
135
+ its(:over_0) { should == [0] }
136
+ its(:over_2000000000) { should == [2000000000] }
137
+
138
+ its(:under_1) { should == [0] }
139
+ its(:under_128) { should == [127] }
140
+ its(:under_2000000000) { should == [1999999999] }
141
+
142
+ its(:over_00) { expect { subject }.to raise_error(NoMethodError) }
143
+ its(:over_01) { expect { subject }.to raise_error(NoMethodError) }
144
+
145
+ it { should_not respond_to(:over_00) }
146
+ it { should_not respond_to(:over_01) }
147
+
148
+ its(:under_0) { expect { subject }.to raise_error(NoMethodError) }
149
+ its(:under_00) { expect { subject }.to raise_error(NoMethodError) }
150
+ its(:under_01) { expect { subject }.to raise_error(NoMethodError) }
151
+
152
+ it { should_not respond_to(:under_0) }
153
+ it { should_not respond_to(:under_00) }
154
+ it { should_not respond_to(:under_01) }
155
+ end
156
+
157
+ describe 2 do
158
+ its(:adult) { should == [-1, -1] }
159
+ its(:adults) { should == [-1, -1] }
160
+
161
+ its(:child) { should == [0, 0] }
162
+ its(:children) { should == [0, 0] }
163
+
164
+ its(:infant) { should == [0, 0] }
165
+ its(:infants) { should == [0, 0] }
166
+
167
+ its(:teenager) { should == [13, 13] }
168
+ its(:teenagers) { should == [13, 13] }
169
+
170
+ its(:senior) { should == [65, 65] }
171
+ its(:seniors) { should == [65, 65] }
172
+
173
+ its(:over_21) { should == [21, 21] }
174
+ its(:over_65) { should == [65, 65] }
175
+
176
+ it { should respond_to(:over_21) }
177
+ it { should respond_to(:over_65) }
178
+
179
+ its(:under_2) { should == [1, 1] }
180
+ its(:under_10) { should == [9, 9] }
181
+ its(:under_12) { should == [11, 11] }
182
+ its(:under_17) { should == [16, 16] }
183
+ its(:under_21) { should == [20, 20] }
184
+
185
+ it { should respond_to(:under_2) }
186
+ it { should respond_to(:under_10) }
187
+ it { should respond_to(:under_12) }
188
+ it { should respond_to(:under_17) }
189
+ it { should respond_to(:under_21) }
190
+ end
191
+
192
+ describe 20 do
193
+ its(:adults) { should == Array.new(described_class).map { -1 } }
194
+ end
195
+
196
+ describe -1 do
197
+ [
198
+ :adult, :adults,
199
+ :child, :children,
200
+ :infant, :infants,
201
+ :teenager, :teenagers,
202
+ :senior, :seniors,
203
+ :over_100, :under_100,
204
+ :over_1, :under_1
205
+ ].each do |method|
206
+ its(method) { expect { subject }.to raise_error(StandardError) }
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler/setup'
2
+ require 'agery'
3
+
4
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: agery
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Chris Griego
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-15 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ requirement: *id001
33
+ name: bundler
34
+ type: :development
35
+ description: Integer extensions for generating arrays of ages.
36
+ email:
37
+ - cgriego@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .autotest
46
+ - .gitignore
47
+ - .rspec
48
+ - Gemfile
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - agery.gemspec
53
+ - lib/agery.rb
54
+ - lib/agery/version.rb
55
+ - spec/agery/version_spec.rb
56
+ - spec/agery_spec.rb
57
+ - spec/spec_helper.rb
58
+ has_rdoc: true
59
+ homepage: https://github.com/cgriego/agery
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project: agery
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Integer extensions for generating arrays of ages.
92
+ test_files:
93
+ - spec/agery/version_spec.rb
94
+ - spec/agery_spec.rb
95
+ - spec/spec_helper.rb