patient-age 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/MIT-LICENSE +16 -0
- data/README +20 -0
- data/Rakefile +26 -0
- data/TODO +3 -0
- data/VERSION +1 -0
- data/lib/patient_age.rb +26 -0
- data/patient-age.gemspec +49 -0
- data/test/patient_age_test.rb +16 -0
- metadata +76 -0
data/.gitignore
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Copyright (c) 2010 Matthew Bass (http://matthewbass.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
4
|
+
and associated documentation files (the "Software"), to deal in the Software without
|
5
|
+
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
6
|
+
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
7
|
+
Software is furnished to do so, subject to the following conditions:
|
8
|
+
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or
|
10
|
+
substantial portions of the Software.
|
11
|
+
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
13
|
+
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
14
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
15
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
= lindo
|
2
|
+
|
3
|
+
Calculates medical patient ages in years, months, weeks and days.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Install the gem standalone:
|
8
|
+
|
9
|
+
sudo gem install patient-age
|
10
|
+
|
11
|
+
Or install the gem in your Rails project:
|
12
|
+
|
13
|
+
config.gem 'patient-age' # add this line to environment.rb
|
14
|
+
rake gems:install
|
15
|
+
|
16
|
+
== Resources
|
17
|
+
|
18
|
+
Repository: http://github.com/pelargir/patient-age
|
19
|
+
Blog: http://matthewbass.com
|
20
|
+
Author: Matthew Bass
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
desc 'Default: run unit tests.'
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
desc 'Test the patient-age gem.'
|
8
|
+
Rake::TestTask.new(:test) do |t|
|
9
|
+
t.libs << 'lib'
|
10
|
+
t.pattern = 'test/**/*_test.rb'
|
11
|
+
t.verbose = true
|
12
|
+
end
|
13
|
+
|
14
|
+
begin
|
15
|
+
require 'jeweler'
|
16
|
+
Jeweler::Tasks.new do |gemspec|
|
17
|
+
gemspec.name = "patient-age"
|
18
|
+
gemspec.summary = "Calculates medical patient ages in years, months, weeks and days."
|
19
|
+
gemspec.description = "Calculates medical patient ages in years, months, weeks and days."
|
20
|
+
gemspec.email = "pelargir@gmail.com"
|
21
|
+
gemspec.homepage = "http://github.com/pelargir/patient-age"
|
22
|
+
gemspec.authors = ["Matthew Bass"]
|
23
|
+
end
|
24
|
+
rescue LoadError
|
25
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
26
|
+
end
|
data/TODO
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
data/lib/patient_age.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module PatientAge
|
4
|
+
def age
|
5
|
+
return "Unknown" if self > 1.day.ago
|
6
|
+
|
7
|
+
now = Time.now
|
8
|
+
years_old = now.year - self.year
|
9
|
+
years_old -= 1 if self.change(:year => now.year) > now
|
10
|
+
return "#{years_old} years" if self < 13.years.ago
|
11
|
+
|
12
|
+
seconds = (now - self) - (years_old * 60 * 60 * 24 * 365.25)
|
13
|
+
months_old = (seconds / 60 / 60 / 24 / 30).abs.floor
|
14
|
+
return "#{years_old} years #{months_old} months" if self < 1.year.ago
|
15
|
+
|
16
|
+
seconds -= (months_old * 60 * 60 * 24 * 30)
|
17
|
+
weeks_old = (seconds / 60 / 60 / 24 / 7).abs.floor
|
18
|
+
return "#{months_old} months #{weeks_old} weeks" if self < 6.months.ago
|
19
|
+
|
20
|
+
weeks_old = ((now - self) / 60 / 60 / 24 / 7).round
|
21
|
+
"#{weeks_old} weeks"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Time.send(:include, PatientAge)
|
26
|
+
DateTime.send(:include, PatientAge)
|
data/patient-age.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{patient-age}
|
8
|
+
s.version = "0.2.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Matthew Bass"]
|
12
|
+
s.date = %q{2010-06-14}
|
13
|
+
s.description = %q{Calculates medical patient ages in years, months, weeks and days.}
|
14
|
+
s.email = %q{pelargir@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README",
|
17
|
+
"TODO"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"MIT-LICENSE",
|
22
|
+
"README",
|
23
|
+
"Rakefile",
|
24
|
+
"TODO",
|
25
|
+
"VERSION",
|
26
|
+
"lib/patient_age.rb",
|
27
|
+
"patient-age.gemspec",
|
28
|
+
"test/patient_age_test.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/pelargir/patient-age}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.7}
|
34
|
+
s.summary = %q{Calculates medical patient ages in years, months, weeks and days.}
|
35
|
+
s.test_files = [
|
36
|
+
"test/patient_age_test.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
else
|
45
|
+
end
|
46
|
+
else
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'patient_age'
|
3
|
+
|
4
|
+
class PatientAgeTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_with_time
|
7
|
+
dob = Time.now - 1.year
|
8
|
+
assert_equal "1 years 0 months", dob.age
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_with_date_time
|
12
|
+
dob = DateTime.now - 6.months
|
13
|
+
assert_equal "6 months 0 weeks", dob.age
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: patient-age
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Matthew Bass
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-14 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Calculates medical patient ages in years, months, weeks and days.
|
23
|
+
email: pelargir@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- README
|
30
|
+
- TODO
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- MIT-LICENSE
|
34
|
+
- README
|
35
|
+
- Rakefile
|
36
|
+
- TODO
|
37
|
+
- VERSION
|
38
|
+
- lib/patient_age.rb
|
39
|
+
- patient-age.gemspec
|
40
|
+
- test/patient_age_test.rb
|
41
|
+
has_rdoc: true
|
42
|
+
homepage: http://github.com/pelargir/patient-age
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options:
|
47
|
+
- --charset=UTF-8
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.7
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Calculates medical patient ages in years, months, weeks and days.
|
75
|
+
test_files:
|
76
|
+
- test/patient_age_test.rb
|