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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +36 -0
  3. data/lib/seniority.rb +83 -62
  4. metadata +7 -8
  5. data/bin/seniority +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d81aeded0ab3d52810746a2d14abe92e3f2db34999805e322eefe039b46dbae
4
- data.tar.gz: 9242e97eee4a369a00e02122fbb431ff4029182b04cbaeb97ae91652dffc4f94
3
+ metadata.gz: 0023d9345027f856d34c33796149b7c27f1b20c142580a0add12f9b5928220a9
4
+ data.tar.gz: 4f2ad10953617d66112a415a6868fb33474a30e974d022a252e2cf3c30f9f943
5
5
  SHA512:
6
- metadata.gz: 9ddd592671673e7e615a88a4c3a5a8b9421f33b10af1ffa4e458e41fad4a084b7eb7dd0b2d7c9b1a650ac60a396feee3d61042c0d7faccab22a128cd0064c9a1
7
- data.tar.gz: f99daef97eebb7490bc54fdbf7f4db6b0b3973b9fff37b50696985264aef7578e3ec96a5c16eb220db20949f3d99847b292061d8c4ae2d1f8310d46014cba84b
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
+ #### [![Gem Version](https://badge.fury.io/rb/seniority@2x.png)](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
- 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(', ')
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
- 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
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
- 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
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
- def self.calculate_year
43
- @year = @current_year - @dob_year
44
- end
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
- 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_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
- 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
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
- def self.borrow_months
73
- 12
74
- end
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.1
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-05 00:00:00.000000000 Z
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
- - bin/seniority
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.3
41
+ rubygems_version: 2.7.6
43
42
  signing_key:
44
43
  specification_version: 4
45
44
  summary: Seniority!
data/bin/seniority DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'seniority'
4
- puts Seniority.introduce()
5
- puts Seniority.get_age(ARGV[0])