adroit-age 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -6
- data/lib/adroit-age.rb +3 -10
- data/lib/adroit-age/api.rb +13 -0
- data/lib/adroit-age/date.rb +7 -0
- metadata +5 -3
data/README.rdoc
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
|
1
|
+
= adroit-age
|
2
2
|
|
3
3
|
{<img src="https://badge.fury.io/rb/adroit-age.png" alt="Gem Version" />}[http://badge.fury.io/rb/adroit-age]
|
4
4
|
|
5
5
|
This gem is used to find the age using date of birth, its also works for leap years.
|
6
6
|
|
7
|
-
|
7
|
+
== Installation
|
8
8
|
|
9
9
|
gem install adroit-age
|
10
10
|
|
@@ -12,11 +12,18 @@ Insert into your gem file
|
|
12
12
|
|
13
13
|
gem "adroit-age"
|
14
14
|
|
15
|
-
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
require 'adroit-age'
|
16
18
|
|
17
|
-
|
19
|
+
dob = Date.new(1990,1,23)
|
20
|
+
or
|
21
|
+
dob = "23/01/1990".to_date
|
18
22
|
|
19
|
-
|
23
|
+
age = dob.find_age
|
24
|
+
#=> 23
|
25
|
+
|
26
|
+
== Contributing to adroit-age
|
20
27
|
|
21
28
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
22
29
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
@@ -26,7 +33,7 @@ Insert into your gem file
|
|
26
33
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
27
34
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
28
35
|
|
29
|
-
|
36
|
+
== Copyright
|
30
37
|
|
31
38
|
Copyright (c) 2013 Raj Adroit. See LICENSE.txt for
|
32
39
|
further details.
|
data/lib/adroit-age.rb
CHANGED
@@ -1,11 +1,4 @@
|
|
1
1
|
require 'active_support/core_ext'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
dob = dob.to_date
|
6
|
-
now = Time.now.utc.to_date
|
7
|
-
age = now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1)
|
8
|
-
raise RuntimeError, 'adroit-age ~> invalid date - Please check the date' if age < 0
|
9
|
-
age
|
10
|
-
end
|
11
|
-
end
|
2
|
+
require 'date'
|
3
|
+
require_relative 'adroit-age/api.rb'
|
4
|
+
require_relative 'adroit-age/date.rb'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Adroit
|
2
|
+
|
3
|
+
class Age
|
4
|
+
attr_accessor :dob, :now, :age
|
5
|
+
|
6
|
+
def find dob
|
7
|
+
@dob = (dob.is_a? String) ? Date.parse(dob) : dob
|
8
|
+
@now = Time.now.utc.to_date
|
9
|
+
@age = @now.year - @dob.year - ((@now.month > @dob.month || (@now.month == @dob.month && @now.day >= @dob.day)) ? 0 : 1)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adroit-age
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
@@ -100,6 +100,8 @@ extra_rdoc_files:
|
|
100
100
|
- README.rdoc
|
101
101
|
files:
|
102
102
|
- lib/adroit-age.rb
|
103
|
+
- lib/adroit-age/api.rb
|
104
|
+
- lib/adroit-age/date.rb
|
103
105
|
- LICENSE.txt
|
104
106
|
- README.rdoc
|
105
107
|
homepage: http://github.com/raj-adroit/adroit-age
|
@@ -117,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
119
|
version: '0'
|
118
120
|
segments:
|
119
121
|
- 0
|
120
|
-
hash: -
|
122
|
+
hash: -979943437
|
121
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
124
|
none: false
|
123
125
|
requirements:
|