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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c2b5248301b702eda2f98967c960369a8474bf4f
4
- data.tar.gz: 9792b9c81e88cd9bbd47d3a8a90cce42fccc72de
3
+ metadata.gz: d12f3865f5ec4b13e5741224475f2aec6118348b
4
+ data.tar.gz: 20e235ce4a969dedc008b076346d0d45ae648745
5
5
  SHA512:
6
- metadata.gz: eb48285de54fc9729e77276af141ab12138782420c69aefbcfc6140016116af9c266732bf3608b12327f0e5abba7f4d53553c60cee68272699d5cb768e855e8d
7
- data.tar.gz: e22245f26a0c1843c792ad63e40c2c7fd424367d8f5c44b2708beecdde23b5bd409b9d7353f061fbf80c38c3a9054afa98edf6a390b1aef4b682260d74554aa1
6
+ metadata.gz: 4798a07ccd1b2c060e9c6409e08bf7b7e0aab4f0b1b221c155a61bd45381d1ab7b354efd233a42ed7704535ca7c1dddab8399d43c89f00c76ec7d19bc3bb9c0e
7
+ data.tar.gz: 43b3edaec2b59632a74a33dc0469920fb3028653721c198bbe008e470c293dc8aa12234196152826d8a88df88c962551d9d967a43c8f3eaaacf628a8a396fd82
@@ -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.
@@ -1,12 +1,47 @@
1
1
  module Adroit
2
-
3
- class Age
4
- attr_accessor :dob, :now, :age
5
-
6
- def find dob
7
- @now = Time.now.utc.to_date
8
- @age = @now.year - dob.year - ((@now.month > dob.month || (@now.month == dob.month && @now.day >= dob.day)) ? 0 : 1)
9
- end
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
@@ -1,7 +1,11 @@
1
1
  class Date
2
2
 
3
3
  def find_age
4
- Adroit::Age.new.find self
4
+ Adroit::Age.new.find_year self
5
+ end
6
+
7
+ def find_age_with_month year_cust = nil, month_cust = nil
8
+ Adroit::Age.new.find_with_month self, year_cust, month_cust
5
9
  end
6
10
 
7
11
  end
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: 1.1.1
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: 2013-12-29 00:00:00.000000000 Z
11
+ date: 2014-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda