seniority 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/lib/seniority.rb +11 -69
- data/lib/seniority/age_finder.rb +63 -0
- metadata +3 -3
- data/README.md +0 -36
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fcbf767f3b187350c31e3008b7e496386ccf1a4760a702e077d9a5630b86fc2c
|
|
4
|
+
data.tar.gz: 0fb28fe2468afd68bab7f0498eaccf5ad58be1b41a88d0fb95747bd9b1857d43
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7cad15b5b1e60655720d417286582a63022edd0f2e2944a9b757e5e086fc852590913309f0432cbf183be8a7b753f36770bb7e720e2fd8f4eb99ac58b54aba7e
|
|
7
|
+
data.tar.gz: ef8ff90bea45ae285f0d0a14de67231ab779938d6b3a2f2771f19a1becc93a8daac5d61a382ec7f46b83973f46ed3f5f5f6464eb9f7370bb8711cd35e375bfc6
|
data/lib/seniority.rb
CHANGED
|
@@ -1,88 +1,30 @@
|
|
|
1
1
|
require 'date'
|
|
2
|
+
|
|
2
3
|
# Age Calculator
|
|
3
4
|
class Seniority
|
|
4
5
|
# method that return calculated age like: "28 year(s), 7 month(s), 1 day(s)"
|
|
5
6
|
def self.get_age(dob)
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
age_finder = AgeCalculator.new(dob)
|
|
8
|
+
age_finder.error.empty? ? "#{age_finder.year} year(s), #{age_finder.month} month(s), #{age_finder.date} day(s)" : age_finder.error
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
# method that return calculated day like: 1
|
|
11
12
|
def self.get_age_day(dob)
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
age_finder = AgeCalculator.new(dob)
|
|
14
|
+
age_finder.error.empty? ? age_finder.date.to_i : age_finder.error
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
# method that return calculated month like: 7
|
|
17
18
|
def self.get_age_month(dob)
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
age_finder = AgeCalculator.new(dob)
|
|
20
|
+
age_finder.error.empty? ? age_finder.month.to_i : age_finder.error
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
# method that return calculated year like: 28
|
|
23
24
|
def self.get_age_year(dob)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def self.age_finder(dob)
|
|
29
|
-
# d1 = Date.parse('2018-07-31') -- Date
|
|
30
|
-
# d2 = '31-07-2018' -- String -- Date.parse(d2)
|
|
31
|
-
# d3 = Time.now -- Time -- d3.to_date
|
|
32
|
-
@error = ''
|
|
33
|
-
begin
|
|
34
|
-
if dob.class == Date
|
|
35
|
-
dob
|
|
36
|
-
elsif dob.class == String
|
|
37
|
-
dob = Date.parse(dob)
|
|
38
|
-
elsif dob.class == Time
|
|
39
|
-
dob = dob.to_date
|
|
40
|
-
else
|
|
41
|
-
@error = 'Invalid Input!'
|
|
42
|
-
end
|
|
43
|
-
rescue
|
|
44
|
-
@error = 'Invalid Input!'
|
|
45
|
-
end
|
|
46
|
-
if @error != 'Invalid Input!'
|
|
47
|
-
@dob_year, @dob_month, @dob_date = dob.year, dob.month, dob.day
|
|
48
|
-
current_date = Time.now.to_date
|
|
49
|
-
@current_year, @current_month, @current_date = current_date.year, current_date.month, current_date.day
|
|
50
|
-
Seniority.calculate_date
|
|
51
|
-
Seniority.calculate_month
|
|
52
|
-
Seniority.calculate_year
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def self.calculate_date
|
|
57
|
-
if @dob_date > @current_date
|
|
58
|
-
@date = (Seniority.borrow_days + @current_date) - @dob_date
|
|
59
|
-
@current_month -= 1
|
|
60
|
-
else
|
|
61
|
-
@date = @current_date - @dob_date
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def self.calculate_month
|
|
66
|
-
if @dob_month > @current_month
|
|
67
|
-
@month = (@current_month + 12) - @dob_month # here 12 is borrowed month
|
|
68
|
-
@current_year -= 1 # after taking 12 months borrow we have to
|
|
69
|
-
# reduce 1 year from current year since 1 year = 12 months
|
|
70
|
-
else
|
|
71
|
-
@month = @current_month - @dob_month
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def self.calculate_year
|
|
76
|
-
@year = @current_year - @dob_year
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def self.borrow_days
|
|
80
|
-
if [1, 3, 5, 7, 8, 10, 12].include?(@current_month)
|
|
81
|
-
31
|
|
82
|
-
elsif [4, 6, 9, 11].include?(@current_month)
|
|
83
|
-
30
|
|
84
|
-
elsif [2].include?(@current_month)
|
|
85
|
-
29 if ((@current_year + 1) % 4).zero?
|
|
86
|
-
end
|
|
25
|
+
age_finder = AgeCalculator.new(dob)
|
|
26
|
+
age_finder.error.empty? ? age_finder.year.to_i : age_finder.error
|
|
87
27
|
end
|
|
88
28
|
end
|
|
29
|
+
|
|
30
|
+
require 'seniority/age_finder'
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
class Seniority::AgeCalculator
|
|
2
|
+
attr_reader :error, :year, :month, :date
|
|
3
|
+
def initialize(dob)
|
|
4
|
+
# d1 = Date.parse('2018-07-31') -- Date
|
|
5
|
+
# d2 = '31-07-2018' -- String -- Date.parse(d2)
|
|
6
|
+
# d3 = Time.now -- Time -- d3.to_date
|
|
7
|
+
@error = ''
|
|
8
|
+
begin
|
|
9
|
+
if dob.class == Date
|
|
10
|
+
dob
|
|
11
|
+
elsif dob.class == String
|
|
12
|
+
dob = Date.parse(dob)
|
|
13
|
+
elsif dob.class == Time
|
|
14
|
+
dob = dob.to_date
|
|
15
|
+
else
|
|
16
|
+
@error = 'Invalid Input!'
|
|
17
|
+
end
|
|
18
|
+
rescue
|
|
19
|
+
@error = 'Invalid Input!'
|
|
20
|
+
end
|
|
21
|
+
if @error != 'Invalid Input!'
|
|
22
|
+
@dob_year, @dob_month, @dob_date = dob.year, dob.month, dob.day
|
|
23
|
+
current_date = Time.now.to_date
|
|
24
|
+
@current_year, @current_month, @current_date = current_date.year, current_date.month, current_date.day
|
|
25
|
+
calculate_date
|
|
26
|
+
calculate_month
|
|
27
|
+
calculate_year
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def calculate_date
|
|
32
|
+
if @dob_date > @current_date
|
|
33
|
+
@date = (borrow_days + @current_date) - @dob_date
|
|
34
|
+
@current_month -= 1
|
|
35
|
+
else
|
|
36
|
+
@date = @current_date - @dob_date
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def calculate_month
|
|
41
|
+
if @dob_month > @current_month
|
|
42
|
+
@month = (@current_month + 12) - @dob_month # here 12 is borrowed month
|
|
43
|
+
@current_year -= 1 # after taking 12 months borrow we have to
|
|
44
|
+
# reduce 1 year from current year since 1 year = 12 months
|
|
45
|
+
else
|
|
46
|
+
@month = @current_month - @dob_month
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def calculate_year
|
|
51
|
+
@year = @current_year - @dob_year
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def borrow_days
|
|
55
|
+
if [1, 3, 5, 7, 8, 10, 12].include?(@current_month)
|
|
56
|
+
31
|
|
57
|
+
elsif [4, 6, 9, 11].include?(@current_month)
|
|
58
|
+
30
|
|
59
|
+
elsif [2].include?(@current_month)
|
|
60
|
+
29 if ((@current_year + 1) % 4).zero?
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: seniority
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Raj Kumar
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-08-
|
|
11
|
+
date: 2018-08-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -30,8 +30,8 @@ executables: []
|
|
|
30
30
|
extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
|
32
32
|
files:
|
|
33
|
-
- README.md
|
|
34
33
|
- lib/seniority.rb
|
|
34
|
+
- lib/seniority/age_finder.rb
|
|
35
35
|
homepage: https://github.com/championrajkumar/seniority
|
|
36
36
|
licenses:
|
|
37
37
|
- MIT
|
data/README.md
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# Seniority
|
|
2
|
-
|
|
3
|
-
## By [Raj Kumar](http://championrajkumar.github.io/)
|
|
4
|
-
|
|
5
|
-
**Seniority** *is a simple gem to find age in format year-month-day till today based on input Date of Birth(DOB)*
|
|
6
|
-
#### [](https://badge.fury.io/rb/seniority)
|
|
7
|
-
* Versions
|
|
8
|
-
* 0.0.1.pre
|
|
9
|
-
* 0.0.1
|
|
10
|
-
* 0.0.2
|
|
11
|
-
* 0.0.3
|
|
12
|
-
* 0.0.4
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Note: Expected Input(DOB) Format: yyyy-mm-dd
|
|
16
|
-
|
|
17
|
-
Available Methods:
|
|
18
|
-
`Seniority.get_age('1989-08-30')`
|
|
19
|
-
=> "28 year(s), 11 month(s), 2 day(s)"
|
|
20
|
-
`Seniority.get_age_day('1989-08-30')`
|
|
21
|
-
=> 2
|
|
22
|
-
`Seniority.get_age_month('1989-08-30')`
|
|
23
|
-
=> 11
|
|
24
|
-
`Seniority.get_age_year('1989-08-30')`
|
|
25
|
-
=> 28
|
|
26
|
-
|
|
27
|
-
**Getting Started:**
|
|
28
|
-
`gem install seniority`<br/>
|
|
29
|
-
`Seniority.get_age('1989-08-30')`<br/>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
**License:**
|
|
33
|
-
[MIT License](https://opensource.org/licenses/MIT)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|