agery 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -10
- data/lib/agery.rb +16 -12
- data/lib/agery/version.rb +1 -1
- data/spec/agery_spec.rb +25 -31
- metadata +18 -10
data/README.md
CHANGED
@@ -16,20 +16,23 @@ price.
|
|
16
16
|
|
17
17
|
## Examples
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
27
|
|
28
28
|
## Customization
|
29
29
|
|
30
30
|
You can override Agery's concept of the age of an adult, infant, child,
|
31
|
-
teenager, and senior by
|
31
|
+
teenager, and senior by setting the Agery accessor of the same name.
|
32
|
+
|
33
|
+
Agery.adult = 18
|
34
|
+
2.adults #=> [18, 18]
|
32
35
|
|
33
36
|
## Installation
|
34
37
|
|
35
|
-
|
38
|
+
`$ gem install agery`
|
data/lib/agery.rb
CHANGED
@@ -1,40 +1,44 @@
|
|
1
1
|
module Agery
|
2
|
-
ADULT = -1
|
3
|
-
INFANT = 0
|
4
|
-
CHILD = 0
|
5
|
-
TEENAGER = 13
|
6
|
-
SENIOR = 65
|
7
|
-
|
8
2
|
AGE_OVER = /^over_(0|[1-9]\d*)$/.freeze
|
9
3
|
AGE_UNDER = /^under_([1-9]\d*)$/.freeze
|
10
4
|
|
5
|
+
@adult = -1
|
6
|
+
@infant = 0
|
7
|
+
@child = 0
|
8
|
+
@teenager = 13
|
9
|
+
@senior = 65
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :adult, :infant, :child, :teenager, :senior
|
13
|
+
end
|
14
|
+
|
11
15
|
def adults
|
12
|
-
to_age_a
|
16
|
+
to_age_a Agery.adult
|
13
17
|
end
|
14
18
|
alias :adult :adults
|
15
19
|
|
16
20
|
def infants
|
17
|
-
to_age_a
|
21
|
+
to_age_a Agery.infant
|
18
22
|
end
|
19
23
|
alias :infant :infants
|
20
24
|
|
21
25
|
def children
|
22
|
-
to_age_a
|
26
|
+
to_age_a Agery.child
|
23
27
|
end
|
24
28
|
alias :child :children
|
25
29
|
|
26
30
|
def teenagers
|
27
|
-
to_age_a
|
31
|
+
to_age_a Agery.teenager
|
28
32
|
end
|
29
33
|
alias :teenager :teenagers
|
30
34
|
|
31
35
|
def seniors
|
32
|
-
to_age_a
|
36
|
+
to_age_a Agery.senior
|
33
37
|
end
|
34
38
|
alias :senior :seniors
|
35
39
|
|
36
40
|
def respond_to?(method, *)
|
37
|
-
AGE_OVER === method.to_s || AGE_UNDER === method.to_s
|
41
|
+
super || AGE_OVER === method.to_s || AGE_UNDER === method.to_s
|
38
42
|
end
|
39
43
|
|
40
44
|
def method_missing(method, *)
|
data/lib/agery/version.rb
CHANGED
data/spec/agery_spec.rb
CHANGED
@@ -1,43 +1,37 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
describe "
|
5
|
-
it {
|
3
|
+
describe Agery do
|
4
|
+
describe ".adult" do
|
5
|
+
it { described_class.adult.should == -1 }
|
6
6
|
end
|
7
7
|
|
8
|
-
describe "
|
9
|
-
it {
|
8
|
+
describe ".infant" do
|
9
|
+
it { described_class.infant.should == 0 }
|
10
10
|
end
|
11
11
|
|
12
|
-
describe "
|
13
|
-
it {
|
12
|
+
describe ".child" do
|
13
|
+
it { described_class.child.should == 0 }
|
14
14
|
end
|
15
15
|
|
16
|
-
describe "
|
17
|
-
it {
|
16
|
+
describe ".teenager" do
|
17
|
+
it { described_class.teenager.should == 13 }
|
18
18
|
end
|
19
19
|
|
20
|
-
describe "
|
21
|
-
it {
|
20
|
+
describe ".senior" do
|
21
|
+
it { described_class.senior.should == 65 }
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
describe "overriding the age
|
25
|
+
describe "overriding the age configuration" do
|
26
26
|
around do |example|
|
27
|
-
|
28
|
-
|
29
|
-
eval "#{constant} = #{age}"
|
30
|
-
$VERBOSE = old_verbose
|
31
|
-
|
27
|
+
old_age = Agery.send(method)
|
28
|
+
Agery.send("#{method}=", age)
|
32
29
|
example.run
|
33
|
-
|
34
|
-
old_verbose, $VERBOSE = $VERBOSE, nil
|
35
|
-
eval "#{constant} = old_age"
|
36
|
-
$VERBOSE = old_verbose
|
30
|
+
Agery.send("#{method}=", old_age)
|
37
31
|
end
|
38
32
|
|
39
|
-
context "
|
40
|
-
let(:
|
33
|
+
context "adult = 21" do
|
34
|
+
let(:method) { :adult }
|
41
35
|
let(:age) { 21 }
|
42
36
|
|
43
37
|
describe 2 do
|
@@ -45,8 +39,8 @@ describe "overriding the age constants" do
|
|
45
39
|
end
|
46
40
|
end
|
47
41
|
|
48
|
-
context "
|
49
|
-
let(:
|
42
|
+
context "infant = -1" do
|
43
|
+
let(:method) { :infant }
|
50
44
|
let(:age) { -1 }
|
51
45
|
|
52
46
|
describe 2 do
|
@@ -54,8 +48,8 @@ describe "overriding the age constants" do
|
|
54
48
|
end
|
55
49
|
end
|
56
50
|
|
57
|
-
context "
|
58
|
-
let(:
|
51
|
+
context "child = 2" do
|
52
|
+
let(:method) { :child }
|
59
53
|
let(:age) { 2 }
|
60
54
|
|
61
55
|
describe 2 do
|
@@ -63,8 +57,8 @@ describe "overriding the age constants" do
|
|
63
57
|
end
|
64
58
|
end
|
65
59
|
|
66
|
-
context "
|
67
|
-
let(:
|
60
|
+
context "teenager = 16" do
|
61
|
+
let(:method) { :teenager }
|
68
62
|
let(:age) { 16 }
|
69
63
|
|
70
64
|
describe 2 do
|
@@ -72,8 +66,8 @@ describe "overriding the age constants" do
|
|
72
66
|
end
|
73
67
|
end
|
74
68
|
|
75
|
-
context "
|
76
|
-
let(:
|
69
|
+
context "senior = 75" do
|
70
|
+
let(:method) { :senior }
|
77
71
|
let(:age) { 75 }
|
78
72
|
|
79
73
|
describe 2 do
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 2.0.0
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Chris Griego
|
@@ -10,20 +15,23 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-16 00:00:00 -05:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
|
-
|
18
|
-
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
19
24
|
none: false
|
20
25
|
requirements:
|
21
26
|
- - ">="
|
22
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
23
31
|
version: "0"
|
32
|
+
requirement: *id001
|
33
|
+
name: bundler
|
24
34
|
type: :development
|
25
|
-
prerelease: false
|
26
|
-
version_requirements: *id001
|
27
35
|
description: Integer extensions for generating arrays of ages.
|
28
36
|
email:
|
29
37
|
- cgriego@gmail.com
|
@@ -61,7 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
69
|
requirements:
|
62
70
|
- - ">="
|
63
71
|
- !ruby/object:Gem::Version
|
64
|
-
hash:
|
72
|
+
hash: 3
|
65
73
|
segments:
|
66
74
|
- 0
|
67
75
|
version: "0"
|
@@ -70,14 +78,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
78
|
requirements:
|
71
79
|
- - ">="
|
72
80
|
- !ruby/object:Gem::Version
|
73
|
-
hash:
|
81
|
+
hash: 3
|
74
82
|
segments:
|
75
83
|
- 0
|
76
84
|
version: "0"
|
77
85
|
requirements: []
|
78
86
|
|
79
87
|
rubyforge_project: agery
|
80
|
-
rubygems_version: 1.
|
88
|
+
rubygems_version: 1.3.7
|
81
89
|
signing_key:
|
82
90
|
specification_version: 3
|
83
91
|
summary: Integer extensions for generating arrays of ages.
|