my_age 0.1.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 94b8a543fa3af2693be174f088a77026200cdd2b
4
- data.tar.gz: df31200e745181d457332916b91d86e519f2bab4
2
+ SHA256:
3
+ metadata.gz: 5d6c4a019d9e132f5052edf89bd2d7a83e6c625940c2814f3474cccd6fc632e5
4
+ data.tar.gz: aec0ea1a792dc609d0588d993d6ad20a4bbe0ffaaf4a95c8815f3535de6e26fc
5
5
  SHA512:
6
- metadata.gz: 1a6e30945d86c319f00c7c8ff9a4a7bcdb5c795fe2ff6c0619fb3dbc1b79e8897e58437b3362721da211412e84a78661b1737c2e65e4f866a99abfb83b1ac286
7
- data.tar.gz: 51639941c07681e648f793eee0e16b21a5dfdc209ee4187ec7c1840b7618bff62c4c3c2ab0923b3b84f7617d8abc1692cb869175a16d32f253270ba759402de2
6
+ metadata.gz: 8d9b5dc50fa470f7f1dc6d361c90d7f591b7566de57c7044a1a40dcc23cb63bd4549aa941259d29ba45a23de2bbcc84912f026875ffde97b532d144b72d0fe73
7
+ data.tar.gz: 4eaa23a13d333ae60a933bf6d5198777092b57dc45b45966070ffe148601cd9951be176d75238a0b0a092e32a1190cbccec3d5f3150d4e85b75faee31161f5e5
@@ -1,14 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support'
2
- require "active_support/core_ext/object/blank"
3
- require "active_support/core_ext/date/calculations"
4
- require "my_age/version"
5
- require "my_age/calculator"
6
- require "my_age/helper"
4
+ require 'active_support/core_ext/object/blank'
5
+ require 'active_support/core_ext/date/calculations'
6
+ require 'my_age/version'
7
+ require 'my_age/calculator'
8
+ require 'my_age/helper'
7
9
 
8
10
  module MyAge
9
- def self.included(base)
10
- base.include MyAge::Calculator
11
- base.include MyAge::Helper
12
- end
13
-
11
+ def self.included(base)
12
+ base.include MyAge::Calculator
13
+ base.include MyAge::Helper
14
+ end
14
15
  end
@@ -1,37 +1,40 @@
1
- require "my_age/helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'my_age/helper'
2
4
 
3
5
  module MyAge
4
- module Calculator
5
-
6
- unless respond_to?(:dob)
7
- def self.included(base)
8
- def base.my_dob(col)
9
- define_method(:dob) { send col }
10
- end
11
- end
12
- end
13
-
14
- def age(date=Date.today)
15
- return 0 if dob.blank? || date.blank? || date <= dob
16
- (date_to_int(date) - date_to_int(dob))/10_000
17
- end
18
-
19
- def method_missing(name, *args)
20
- if name.to_s =~ /_as_of_/
21
- date_method = name.to_s.split("_as_of_")[-1]
22
- age today.send(date_method.to_sym, *args)
23
- else
24
- super
25
- end
26
- end
27
-
28
- private
29
- def date_to_int(date)
30
- date.strftime("%Y%m%d").to_i
31
- end
32
-
33
- def today
34
- Date.today
35
- end
36
- end
6
+ module Calculator
7
+ unless respond_to?(:dob)
8
+ def self.included(base)
9
+ def base.my_dob(col)
10
+ define_method(:dob) { send col }
11
+ end
12
+ end
13
+ end
14
+
15
+ def age(date = Date.today)
16
+ return 0 if dob.blank? || date.blank? || date <= dob
17
+
18
+ (date_to_int(date) - date_to_int(dob)) / 10_000
19
+ end
20
+
21
+ def method_missing(name, *args)
22
+ if name.to_s =~ /_as_of_/
23
+ date_method = name.to_s.split('_as_of_')[-1]
24
+ age today.send(date_method.to_sym, *args)
25
+ else
26
+ super
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def date_to_int(date)
33
+ date.strftime('%Y%m%d').to_i
34
+ end
35
+
36
+ def today
37
+ Date.today
38
+ end
39
+ end
37
40
  end
@@ -1,37 +1,39 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
  require 'my_age'
3
5
  module MyAge
4
- class CLI < Thor
5
- attr_accessor :dob
6
- include MyAge::Calculator
6
+ class CLI < Thor
7
+ attr_accessor :dob
8
+ include MyAge::Calculator
7
9
 
8
- desc "is AGE", "-d date_of_birth -a as_of_date, Dates are in yyyy-mm-dd format"
9
- method_option :dob, aliases: "d", desc: "date of birth in yyyy-mm-dd", required: true
10
- method_option :as_of, aliases: "a", desc: "as of date in yyyy-mm-dd", required: false
11
- def is
12
- self.dob = get_date(options[:dob])
13
- date = options[:as_of].present? ? get_date(options[:as_of]) : Date.today
14
- puts self.age(date)
15
- end
10
+ desc 'is AGE', '-d date_of_birth -a as_of_date, Dates are in yyyy-mm-dd format'
11
+ method_option :dob, aliases: 'd', desc: 'date of birth in yyyy-mm-dd', required: true
12
+ method_option :as_of, aliases: 'a', desc: 'as of date in yyyy-mm-dd', required: false
13
+ def is
14
+ self.dob = get_date(options[:dob])
15
+ date = options[:as_of].present? ? get_date(options[:as_of]) : Date.today
16
+ puts age(date)
17
+ end
16
18
 
17
- private
18
- def get_date(date)
19
- if date =~ /^\d{4}-\d{2}-\d{2}$/
20
- DateTime.strptime(date, "%Y-%m-%d")
21
- else
22
- date_from_active_support_core_ext_helper(date)
23
- end
24
- rescue NoMethodError
25
- Date.send(date)
26
- end
19
+ private
27
20
 
28
- def date_from_active_support_core_ext_helper(date)
29
- dates = date.delete(")").split("(")
30
- method = dates[0].to_sym
31
- arg = dates[1]
32
- arg.nil? ? Date.today.send(method) :
33
- Date.today.send(method, arg.to_i)
34
- end
21
+ def get_date(date)
22
+ if date =~ /^\d{4}-\d{2}-\d{2}$/
23
+ DateTime.strptime(date, '%Y-%m-%d')
24
+ else
25
+ date_from_active_support_core_ext_helper(date)
26
+ end
27
+ rescue NoMethodError
28
+ Date.send(date)
29
+ end
35
30
 
36
- end
31
+ def date_from_active_support_core_ext_helper(date)
32
+ dates = date.delete(')').split('(')
33
+ method = dates[0].to_sym
34
+ arg = dates[1]
35
+ arg.nil? ? Date.today.send(method) :
36
+ Date.today.send(method, arg.to_i)
37
+ end
38
+ end
37
39
  end
@@ -1,10 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MyAge
2
4
  module Helper
3
-
4
- def age_as_of_today
5
- age
6
- end
7
-
8
-
5
+ def age_as_of_today
6
+ age
7
+ end
9
8
  end
10
9
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MyAge
2
- VERSION = "0.1.6"
4
+ VERSION = '1.0.0'
3
5
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_dependency "activesupport", ">= 4.2"
27
27
  spec.add_dependency "thor", "~>0.20.0"
28
28
  spec.add_development_dependency "bundler", "~> 1.13"
29
- spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rake", "~> 12.3.3"
30
30
  spec.add_development_dependency "rspec", "~> 3.0"
31
31
  spec.add_development_dependency "pry", "~>0.11"
32
32
  spec.add_development_dependency "cucumber", "~>3.1.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_age
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-31 00:00:00.000000000 Z
11
+ date: 2020-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: 12.3.3
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: 12.3.3
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -167,8 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubyforge_project:
171
- rubygems_version: 2.6.14
170
+ rubygems_version: 3.0.3
172
171
  signing_key:
173
172
  specification_version: 4
174
173
  summary: Calculate my age.