seniority 0.0.1 → 0.0.2
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/README.md +36 -0
- data/lib/seniority.rb +83 -62
- metadata +7 -8
- data/bin/seniority +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0023d9345027f856d34c33796149b7c27f1b20c142580a0add12f9b5928220a9
|
|
4
|
+
data.tar.gz: 4f2ad10953617d66112a415a6868fb33474a30e974d022a252e2cf3c30f9f943
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5cbd1918e026181843d7da0c06c822713a694c7716a9caa09f3afe164b368c3cde613dd27517d445a9c71d77805c8b9703db885246ee0ea9e5ed1307e68686ee
|
|
7
|
+
data.tar.gz: 86bcd5c0291c32a77e93d4fb225485e5fa13e213850d1ee2ec283391917f325b77abf87eaa931491d1fe388257068ec0f7327814da6518d160c45d668ecffec2
|
data/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
|
|
11
|
+
Note: Expected Input(DOB) Format: yyyy-mm-dd
|
|
12
|
+
|
|
13
|
+
Available Methods:
|
|
14
|
+
`Seniority.get_textual_age('1989-08-30')`
|
|
15
|
+
=> "28 year(s), 7 month(s), 1 day(s)"
|
|
16
|
+
`Seniority.get_age('1989-08-30')`
|
|
17
|
+
=> 28-07-01 (in yyyy-mm-dd)
|
|
18
|
+
`Seniority.get_age_day('1989-08-30')`
|
|
19
|
+
=> 01
|
|
20
|
+
`Seniority.get_age_month('1989-08-30')`
|
|
21
|
+
=> 07
|
|
22
|
+
`Seniority.get_age_year('1989-08-30')`
|
|
23
|
+
=> 28
|
|
24
|
+
|
|
25
|
+
**Getting Started:**
|
|
26
|
+
`gem install seniority -v 0.0.2`<br/>
|
|
27
|
+
Or
|
|
28
|
+
`gem '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
|
+
|
data/lib/seniority.rb
CHANGED
|
@@ -1,75 +1,96 @@
|
|
|
1
1
|
class Seniority
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
2
|
+
#method that return result(in yyyy-mm-dd) as: 28-07-01
|
|
3
|
+
def self.get_age(dob)
|
|
4
|
+
Seniority.age_finder dob
|
|
5
|
+
@err_mess.any? ? @err_mess.join(', ') : "#{@year}-#{@month}-#{@date}"
|
|
6
|
+
end
|
|
7
|
+
#method that return result as: "28 year(s), 7 month(s), 1 day(s)"
|
|
8
|
+
def self.get_textual_age(dob)
|
|
9
|
+
Seniority.age_finder dob
|
|
10
|
+
@err_mess.any? ? @err_mess.join(', ') : "#{@year} year(s), #{@month} month(s), #{@date} day(s)"
|
|
11
|
+
end
|
|
12
|
+
#method that return result as: "1"
|
|
13
|
+
def self.get_age_day(dob)
|
|
14
|
+
Seniority.age_finder dob
|
|
15
|
+
@err_mess.any? ? @err_mess.join(', ') : "#{@date}"
|
|
16
|
+
end
|
|
17
|
+
#method that return result as: "7"
|
|
18
|
+
def self.get_age_month(dob)
|
|
19
|
+
Seniority.age_finder dob
|
|
20
|
+
@err_mess.any? ? @err_mess.join(', ') : "#{@month}"
|
|
21
|
+
end
|
|
22
|
+
#method that return result as: "28"
|
|
23
|
+
def self.get_age_year(dob)
|
|
24
|
+
Seniority.age_finder dob
|
|
25
|
+
@err_mess.any? ? @err_mess.join(', ') : "#{@year}"
|
|
21
26
|
end
|
|
22
|
-
end
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
def self.age_finder dob
|
|
29
|
+
@err_mess = []
|
|
30
|
+
# expected input dob as: '1987-21-05' i.e. yyyy-mm-dd
|
|
31
|
+
@dob_year, @dob_month, @dob_date = dob.split('-')
|
|
32
|
+
@current_year, @current_month, @current_date = Time.now.strftime("%Y-%m-%d").split('-')
|
|
33
|
+
@current_year, @current_month, @current_date = @current_year.to_i, @current_month.to_i, @current_date.to_i
|
|
34
|
+
Seniority.get_error
|
|
35
|
+
if !@err_mess.any?
|
|
36
|
+
@dob_year, @dob_month, @dob_date = @dob_year.to_i, @dob_month.to_i, @dob_date.to_i
|
|
37
|
+
Seniority.calculate_date; Seniority.calculate_month; Seniority.calculate_year
|
|
38
|
+
else
|
|
39
|
+
@err_mess.join(', ')
|
|
40
|
+
end
|
|
30
41
|
end
|
|
31
|
-
end
|
|
32
42
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
def self.calculate_date
|
|
44
|
+
if @dob_date > @current_date
|
|
45
|
+
@date = (Seniority.borrow_days + @current_date) - @dob_date
|
|
46
|
+
@current_month = @current_month - 1
|
|
47
|
+
else
|
|
48
|
+
@date = @current_date - @dob_date
|
|
49
|
+
end
|
|
39
50
|
end
|
|
40
|
-
end
|
|
41
51
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
def self.calculate_month
|
|
53
|
+
if @dob_month > @current_month
|
|
54
|
+
@month = (@current_month + 12) - @dob_month # here 12 is borrowed month
|
|
55
|
+
@current_year = @current_year - 1 # after taking 12 months borrow we have to reduce 1 year from current year since 1 year = 12 months
|
|
56
|
+
else
|
|
57
|
+
@month = @current_month - @dob_month
|
|
58
|
+
end
|
|
59
|
+
end
|
|
45
60
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
@err_mess << 'DOB year is greater than current year. '
|
|
49
|
-
elsif @dob_year.to_i <= 0
|
|
50
|
-
@err_mess << 'DOB year is not valid. '
|
|
51
|
-
elsif @dob_month.to_i <= 0
|
|
52
|
-
@err_mess << 'DOB month is not valid. '
|
|
53
|
-
elsif @dob_date.to_i <= 0
|
|
54
|
-
@err_mess << 'DOB date is not valid. '
|
|
61
|
+
def self.calculate_year
|
|
62
|
+
@year = @current_year - @dob_year
|
|
55
63
|
end
|
|
56
|
-
end
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
def self.get_error
|
|
66
|
+
# check any non-digit in year, month and day
|
|
67
|
+
# check day, month and year should not be zero
|
|
68
|
+
# check month and day should be within range i.e. for month: 12 and for day: 31
|
|
69
|
+
if !(@dob_year.scan(/\D/).empty?) or @dob_year.to_i == 0
|
|
70
|
+
@err_mess << 'DOB year is not valid'
|
|
71
|
+
end
|
|
72
|
+
if !(@dob_month.scan(/\D/).empty?) or @dob_month.to_i == 0 or @dob_month.to_i > 12
|
|
73
|
+
@err_mess << 'DOB month is not valid'
|
|
74
|
+
end
|
|
75
|
+
if !(@dob_date.scan(/\D/).empty?) or @dob_date.to_i == 0 or @dob_date.to_i > 31
|
|
76
|
+
@err_mess << 'DOB date is not valid'
|
|
77
|
+
end
|
|
78
|
+
# check dob should be less than current_year
|
|
79
|
+
if @dob_year.to_i > @current_year
|
|
80
|
+
@err_mess << 'DOB year is greater than current year'
|
|
81
|
+
end
|
|
69
82
|
end
|
|
70
|
-
end
|
|
71
83
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
def self.borrow_days
|
|
85
|
+
if [1, 3, 5, 7, 8, 10, 12].include?(@current_month)
|
|
86
|
+
31
|
|
87
|
+
elsif [4, 6, 9, 11].include?(@current_month)
|
|
88
|
+
30
|
|
89
|
+
elsif [2].include?(@current_month)
|
|
90
|
+
if ((@current_year+1) % 4) == 0
|
|
91
|
+
29
|
|
92
|
+
elsif 28
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
75
96
|
end
|
metadata
CHANGED
|
@@ -1,29 +1,28 @@
|
|
|
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.2
|
|
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-03-
|
|
11
|
+
date: 2018-03-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description: A simple gem to calculate age from DOB
|
|
13
|
+
description: A simple gem to calculate current age from input DOB(Date of Birth)
|
|
14
14
|
email: raj4057kumar@gmail.com
|
|
15
|
-
executables:
|
|
16
|
-
- seniority
|
|
15
|
+
executables: []
|
|
17
16
|
extensions: []
|
|
18
17
|
extra_rdoc_files: []
|
|
19
18
|
files:
|
|
20
|
-
-
|
|
19
|
+
- README.md
|
|
21
20
|
- lib/seniority.rb
|
|
22
21
|
homepage: http://rubygems.org/gems/seniority
|
|
23
22
|
licenses:
|
|
24
23
|
- MIT
|
|
25
24
|
metadata: {}
|
|
26
|
-
post_install_message:
|
|
25
|
+
post_install_message: Thanks for installing Seniority.
|
|
27
26
|
rdoc_options: []
|
|
28
27
|
require_paths:
|
|
29
28
|
- lib
|
|
@@ -39,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
39
38
|
version: '0'
|
|
40
39
|
requirements: []
|
|
41
40
|
rubyforge_project:
|
|
42
|
-
rubygems_version: 2.7.
|
|
41
|
+
rubygems_version: 2.7.6
|
|
43
42
|
signing_key:
|
|
44
43
|
specification_version: 4
|
|
45
44
|
summary: Seniority!
|