seniority 0.0.3 → 0.0.4

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