my_age 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cbaaa4ed9c99329e358feb2b5b99e8e705aa6dda
4
+ data.tar.gz: 0e631ba5c69de82f1cab2d57f85368480404fb11
5
+ SHA512:
6
+ metadata.gz: 41429b2a04e1aa215369d4edb63c76de4cc7ca5dab94789a4fe6f85c9ed4d300467701f54f134023d7fab29e86b2c5056940de4f3b6a1794ba52d298beab12c4
7
+ data.tar.gz: 98f11244ea82923f0d5ff731865b27cf76cc679f4db1520773bd6b4c7b13c7b5d1b73cc536584536695d8d824f942bc879618e1600dfc3dd4b96719476c7da3f
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.DS_Store
11
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.13.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in my_age.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Edgar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # MyAge
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/my_age`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'my_age'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install my_age
22
+
23
+ ## Usage
24
+
25
+ Mixin the calculator module
26
+
27
+ ```
28
+ class User
29
+ attr_accessor :dob
30
+ include MyAge::Calculator
31
+ end
32
+
33
+ user = User.new
34
+ user.age
35
+ ## age as of today
36
+ user.age(date)
37
+ ## age as of date
38
+ user.age_as_of_tomorrow
39
+ ## age as of tomorrow
40
+ ```
41
+
42
+ Use you own dob attribute
43
+
44
+ ```
45
+ class User
46
+ attr_accessor :date_of_birth
47
+ include MyAge::Calculator
48
+ my_dob :date_of_birth
49
+ end
50
+
51
+ ##everything else is the same
52
+ ```
53
+
54
+
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
+
60
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/my_age.
65
+
66
+
67
+ ## License
68
+
69
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
70
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "my_age"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/my_age ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'my_age/cli'
3
+ MyAge::CLI.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ require "my_age/helper"
2
+
3
+ module MyAge
4
+ module Calculator
5
+ include MyAge::Helper
6
+
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
+ (date_to_int(date) - date_to_int(dob))/10_000
18
+ end
19
+
20
+ def method_missing(name, *args)
21
+ if name.to_s =~ /_as_of_/
22
+ date_method = name.to_s.split("_as_of_")[-1]
23
+ age today.send(date_method.to_sym, *args)
24
+ else
25
+ super
26
+ end
27
+ end
28
+
29
+ private
30
+ def date_to_int(date)
31
+ date.strftime("%Y%m%d").to_i
32
+ end
33
+
34
+ def today
35
+ Date.today
36
+ end
37
+ end
38
+ end
data/lib/my_age/cli.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'thor'
2
+ require 'my_age'
3
+
4
+ module MyAge
5
+ class CLI < Thor
6
+ attr_accessor :dob
7
+ include MyAge::Calculator
8
+
9
+ desc "is AGE", "-d date_of_birth -a as_of_date, Dates are in yyyy-mm-dd format"
10
+ method_option :dob, aliases: "d", desc: "date of birth in yyyy-mm-dd", required: true
11
+ method_option :as_of, aliases: "a", desc: "as of date in yyyy-mm-dd", required: true
12
+ def is
13
+ self.dob = DateTime.strptime(options[:dob], "%Y-%m-%d")
14
+ date = DateTime.strptime(options[:as_of], "%Y-%m-%d")
15
+ puts self.age(date)
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ module MyAge
2
+ module Helper
3
+
4
+ def age_as_of_today
5
+ age
6
+ end
7
+
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module MyAge
2
+ VERSION = "0.1.0"
3
+ end
data/lib/my_age.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "active_support/core_ext/object"
2
+ require "active_support/core_ext/date_and_time/calculations"
3
+ require "my_age/version"
4
+ require "my_age/calculator"
5
+ require "my_age/helper"
6
+
7
+ module MyAge
8
+
9
+ end
data/my_age.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'my_age/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "my_age"
8
+ spec.version = MyAge::VERSION
9
+ spec.authors = ["Edgar"]
10
+ spec.email = ["zorro.ej@gmail.com"]
11
+
12
+ spec.summary = %q{Calculate my age.}
13
+ spec.description = %q{Default calendr: Gregorian. Though would like to expand to other calendars too}
14
+ spec.homepage = "https://github.com/ej2015/my_age.git"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "activesupport", ">= 4.2"
25
+ spec.add_dependency "thor"
26
+ spec.add_development_dependency "bundler", "~> 1.13"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "pry", "~>0.11"
30
+ spec.add_development_dependency "cucumber"
31
+ spec.add_development_dependency "aruba"
32
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: my_age
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Edgar
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.11'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.11'
97
+ - !ruby/object:Gem::Dependency
98
+ name: cucumber
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: aruba
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: 'Default calendr: Gregorian. Though would like to expand to other calendars
126
+ too'
127
+ email:
128
+ - zorro.ej@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - bin/console
141
+ - bin/my_age
142
+ - bin/setup
143
+ - lib/my_age.rb
144
+ - lib/my_age/calculator.rb
145
+ - lib/my_age/cli.rb
146
+ - lib/my_age/helper.rb
147
+ - lib/my_age/version.rb
148
+ - my_age.gemspec
149
+ homepage: https://github.com/ej2015/my_age.git
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.6.14
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Calculate my age.
173
+ test_files: []