agery 1.0.1 → 2.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.
Files changed (5) hide show
  1. data/README.md +13 -10
  2. data/lib/agery.rb +16 -12
  3. data/lib/agery/version.rb +1 -1
  4. data/spec/agery_spec.rb +25 -31
  5. metadata +18 -10
data/README.md CHANGED
@@ -16,20 +16,23 @@ price.
16
16
 
17
17
  ## Examples
18
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]`
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 overriding the Agery constant of the same name.
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
- `gem install agery`
38
+ `$ gem install agery`
@@ -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 ADULT
16
+ to_age_a Agery.adult
13
17
  end
14
18
  alias :adult :adults
15
19
 
16
20
  def infants
17
- to_age_a INFANT
21
+ to_age_a Agery.infant
18
22
  end
19
23
  alias :infant :infants
20
24
 
21
25
  def children
22
- to_age_a CHILD
26
+ to_age_a Agery.child
23
27
  end
24
28
  alias :child :children
25
29
 
26
30
  def teenagers
27
- to_age_a TEENAGER
31
+ to_age_a Agery.teenager
28
32
  end
29
33
  alias :teenager :teenagers
30
34
 
31
35
  def seniors
32
- to_age_a SENIOR
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 || super
41
+ super || AGE_OVER === method.to_s || AGE_UNDER === method.to_s
38
42
  end
39
43
 
40
44
  def method_missing(method, *)
@@ -1,3 +1,3 @@
1
1
  module Agery
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,43 +1,37 @@
1
1
  require 'spec_helper'
2
2
 
3
- module Agery
4
- describe "Agery::ADULT" do
5
- it { Agery::ADULT.should == -1 }
3
+ describe Agery do
4
+ describe ".adult" do
5
+ it { described_class.adult.should == -1 }
6
6
  end
7
7
 
8
- describe "Agery::INFANT" do
9
- it { Agery::INFANT.should == 0 }
8
+ describe ".infant" do
9
+ it { described_class.infant.should == 0 }
10
10
  end
11
11
 
12
- describe "Agery::CHILD" do
13
- it { Agery::CHILD.should == 0 }
12
+ describe ".child" do
13
+ it { described_class.child.should == 0 }
14
14
  end
15
15
 
16
- describe "Agery::TEENAGER" do
17
- it { Agery::TEENAGER.should == 13 }
16
+ describe ".teenager" do
17
+ it { described_class.teenager.should == 13 }
18
18
  end
19
19
 
20
- describe "Agery::SENIOR" do
21
- it { Agery::SENIOR.should == 65 }
20
+ describe ".senior" do
21
+ it { described_class.senior.should == 65 }
22
22
  end
23
23
  end
24
24
 
25
- describe "overriding the age constants" do
25
+ describe "overriding the age configuration" do
26
26
  around do |example|
27
- old_verbose, $VERBOSE = $VERBOSE, nil
28
- old_age = eval(constant)
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 "ADULT = 21" do
40
- let(:constant) { "Agery::ADULT" }
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 "INFANT = -1" do
49
- let(:constant) { "Agery::INFANT" }
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 "CHILD = 2" do
58
- let(:constant) { "Agery::CHILD" }
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 "TEENAGER = 16" do
67
- let(:constant) { "Agery::TEENAGER" }
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 "SENIOR = 75" do
76
- let(:constant) { "Agery::SENIOR" }
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
- prerelease:
5
- version: 1.0.1
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-15 00:00:00 -05:00
18
+ date: 2011-03-16 00:00:00 -05:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
- name: bundler
18
- requirement: &id001 !ruby/object:Gem::Requirement
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: -574640053356968737
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: -574640053356968737
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.5.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.