adroit-age 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +12 -0
- data/lib/adroit-age/api.rb +43 -8
- data/lib/adroit-age/date.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d12f3865f5ec4b13e5741224475f2aec6118348b
|
4
|
+
data.tar.gz: 20e235ce4a969dedc008b076346d0d45ae648745
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4798a07ccd1b2c060e9c6409e08bf7b7e0aab4f0b1b221c155a61bd45381d1ab7b354efd233a42ed7704535ca7c1dddab8399d43c89f00c76ec7d19bc3bb9c0e
|
7
|
+
data.tar.gz: 43b3edaec2b59632a74a33dc0469920fb3028653721c198bbe008e470c293dc8aa12234196152826d8a88df88c962551d9d967a43c8f3eaaacf628a8a396fd82
|
data/README.rdoc
CHANGED
@@ -23,6 +23,18 @@ Insert into your gem file
|
|
23
23
|
age = dob.find_age
|
24
24
|
#=> 23
|
25
25
|
|
26
|
+
== Update v2.0
|
27
|
+
|
28
|
+
dob.find_age_with_month
|
29
|
+
#=> "23 years and 11 months"
|
30
|
+
|
31
|
+
dob.find_age_with_month("y","m")
|
32
|
+
#=> "23 y and 11 m"
|
33
|
+
|
34
|
+
dob.find_age_with_month
|
35
|
+
#=> "23 years and 1 month"
|
36
|
+
|
37
|
+
|
26
38
|
== Contributing to adroit-age
|
27
39
|
|
28
40
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
data/lib/adroit-age/api.rb
CHANGED
@@ -1,12 +1,47 @@
|
|
1
1
|
module Adroit
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
|
3
|
+
class Age
|
4
|
+
|
5
|
+
attr_accessor :dob, :now, :age
|
6
|
+
@@now = Time.now.utc.to_date
|
7
|
+
def find_year dob
|
8
|
+
age = @@now.year - dob.year - ((full_year? dob) ? 0 : 1)
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_with_month dob, year_cust, month_cust
|
12
|
+
year = find_year dob
|
13
|
+
month = find_month dob
|
14
|
+
month_cust_label = month_cust.nil? ? "#{month_label month}" : month_cust
|
15
|
+
year_cust_label = year_cust.nil? ? "#{year_label year}" : year_cust
|
16
|
+
"#{year} #{year_cust_label} and #{month} #{month_cust_label}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_month dob
|
20
|
+
if @@now.month == dob.month
|
21
|
+
0
|
22
|
+
elsif @@now.month < dob.month
|
23
|
+
((12 - dob.month) + @@now.month) - ((full_month? dob.day) ? 0 : 1)
|
24
|
+
elsif @@now.month > dob.month
|
25
|
+
(@@now.month - dob.month) - ((full_month? dob.day) ? 0 : 1)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def year_label year
|
30
|
+
year == 1 ? "year" : "years"
|
31
|
+
end
|
32
|
+
|
33
|
+
def month_label month
|
34
|
+
month == 1 ? "month" : "months"
|
35
|
+
end
|
36
|
+
|
37
|
+
def full_month? day
|
38
|
+
(@@now.day > day || @@now.day == day)
|
39
|
+
end
|
40
|
+
|
41
|
+
def full_year? dob
|
42
|
+
(@@now.month > dob.month || (@@now.month == dob.month && @@now.day >= dob.day))
|
43
|
+
end
|
44
|
+
|
10
45
|
end
|
11
46
|
|
12
47
|
end
|
data/lib/adroit-age/date.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adroit-age
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raj Adroit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|