seniority 0.0.1.pre
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 +7 -0
- data/bin/seniority +5 -0
- data/lib/seniority.rb +75 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1c5f3b10672dfc201c2da443c6ed0a4b0215850cb8c925d3c20f023125bdc540
|
|
4
|
+
data.tar.gz: 9129d5732a2eaa99f5050bbff7daf35b1eaf1a06d47f63e525d6e59d74d50da5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d4d11b3fcb859122da6933ea24385e85f1feb3af31373613ff4c7dc3de86e9813d2df190fff21f6d34f899ee70cf8e3350f7d416d51f70c4cb3863c7539e7565
|
|
7
|
+
data.tar.gz: 7f3271ef20110a956cb59902ec495a240c4290d0c7dc40ec3d37889bb4345fdec4becd5afcb754bec729d4449baf1f0414aef79e2a35a37e04e2e48bfedf8495
|
data/bin/seniority
ADDED
data/lib/seniority.rb
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
class Seniority
|
|
2
|
+
def self.introduce
|
|
3
|
+
puts"This is age(in format day-month-year) finder from Date of Birth(DOB in format 'yyyy-mm-dd'). Call method find_age('yyyy-mm-dd') as find_age('1989-08-30's)"
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def self.get_age(dob, timezone=nil)
|
|
7
|
+
@err_mess = []
|
|
8
|
+
# dob = '1987-21-05'
|
|
9
|
+
# today date = '2018-03-05'
|
|
10
|
+
# output = ["15-9-30", "15 day(s) 9 month(s) 30 year(s)"]
|
|
11
|
+
@dob_year, @dob_month, @dob_date = dob.split('-')
|
|
12
|
+
@current_year, @current_month, @current_date = Time.now.strftime("%Y-%m-%d").split('-')
|
|
13
|
+
@current_year, @current_month, @current_date = @current_year.to_i, @current_month.to_i, @current_date.to_i
|
|
14
|
+
@dob_year, @dob_month, @dob_date = @dob_year.to_i, @dob_month.to_i, @dob_date.to_i
|
|
15
|
+
Seniority.get_error
|
|
16
|
+
if !@err_mess.any?
|
|
17
|
+
Seniority.calculate_date;Seniority.calculate_month;Seniority.calculate_year
|
|
18
|
+
return ["#{@date}-#{@month}-#{@year}", "#{@date} day(s) #{@month} month(s) #{@year} year(s)"]
|
|
19
|
+
else
|
|
20
|
+
@err_mess.join(', ')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.calculate_date
|
|
25
|
+
if @dob_date > @current_date
|
|
26
|
+
@date = (Seniority.borrow_days + @current_date) - @dob_date
|
|
27
|
+
@current_month = @current_month - 1
|
|
28
|
+
else
|
|
29
|
+
@date = @current_date - @dob_date
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.calculate_month
|
|
34
|
+
if @dob_month > @current_month
|
|
35
|
+
@month = (@current_month + Seniority.borrow_months) - @dob_month
|
|
36
|
+
@current_year = @current_year - 1
|
|
37
|
+
else
|
|
38
|
+
@month = @current_month - @dob_month
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.calculate_year
|
|
43
|
+
@year = @current_year - @dob_year
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.get_error
|
|
47
|
+
if @dob_year > @current_year
|
|
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_year.to_i <= 0
|
|
54
|
+
@err_mess << 'DOB date is not valid. '
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def self.borrow_days
|
|
59
|
+
if [1, 3, 5, 7, 8, 10, 12].include?(@current_month)
|
|
60
|
+
31
|
|
61
|
+
elsif [4, 6, 9, 11].include?(@current_month)
|
|
62
|
+
30
|
|
63
|
+
elsif [2].include?(@current_month)
|
|
64
|
+
if ((@current_year+1) % 4) == 0
|
|
65
|
+
29
|
|
66
|
+
elsif
|
|
67
|
+
28
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.borrow_months
|
|
73
|
+
12
|
|
74
|
+
end
|
|
75
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: seniority
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1.pre
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Raj Kumar
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-03-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A simple gem to calculate age from DOB
|
|
14
|
+
email: raj4057kumar@gmail.com
|
|
15
|
+
executables:
|
|
16
|
+
- seniority
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- bin/seniority
|
|
21
|
+
- lib/seniority.rb
|
|
22
|
+
homepage: http://rubygems.org/gems/seniority
|
|
23
|
+
licenses:
|
|
24
|
+
- MIT
|
|
25
|
+
metadata: {}
|
|
26
|
+
post_install_message:
|
|
27
|
+
rdoc_options: []
|
|
28
|
+
require_paths:
|
|
29
|
+
- lib
|
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 1.3.1
|
|
40
|
+
requirements: []
|
|
41
|
+
rubyforge_project:
|
|
42
|
+
rubygems_version: 2.7.3
|
|
43
|
+
signing_key:
|
|
44
|
+
specification_version: 4
|
|
45
|
+
summary: Seniority!
|
|
46
|
+
test_files: []
|