bmicalc-qwertme 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d11c66a444b173f7aff443dd11fc4d4dbcac885
4
+ data.tar.gz: 631f9f011cdfc4538a8068dd819bf309fa0589f6
5
+ SHA512:
6
+ metadata.gz: be20f3ada5b5e307fdd64da9e46046d9c5a52cb4f461faf6c55a7334afbd2a6b9f2d2eeaa54beb3f5e227d96b9eb6769ac04871ac772571237d6b83a2a8d32d8
7
+ data.tar.gz: 8fb46099878095ada9fad2cdf3795ec71af39894a4f4e1d3e4070891d8241874c12f324bd887ac7eb3b2759b48189134566079d24a1935ade3d89f1474f380db
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-2.1.2@bmicalc --create --install
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bmicalc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tom Kadwill
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ Bmi Calc
2
+ =======
3
+
4
+ Gem to calculate BMI
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'bmicalc'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install bmicalc-qwertme
19
+
20
+ ## Usage
21
+
22
+ ### Metric
23
+ require 'bmicalc'
24
+
25
+ bmi = Bmicalc.new
26
+ bmi.calculate(64, 178) # 20.199469763918696
27
+
28
+ ### Imperial
29
+
30
+ bmi = Bmicalc.new(units: :imperial)
31
+ bmi.calculate(141, 71) # ~20
32
+
33
+ ### WHO BMI classification
34
+
35
+ bmi = Bmicalc.new
36
+ bmi.classification(27) # 'overweight'
37
+ bmi.sub_classification(27) # 'pre-obese'
38
+
39
+ Forked from http://github.com/tomkadwill/bmicalc and heavily modified
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Dir.glob('tasks/**/*.rake').each(&method(:import))
4
+
5
+ task default: :spec
data/bmicalc.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bmicalc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bmicalc-qwertme"
8
+ spec.version = Bmicalc::VERSION
9
+ spec.authors = ["Eric di Domenico"]
10
+ spec.email = ["eric@didomenico.com"]
11
+ spec.summary = %q{Calculate BMI}
12
+ spec.description = %q{Calculate BMI}
13
+ spec.homepage = "https://github.com/qwertme/bmicalc.git"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
data/lib/bmicalc.rb ADDED
@@ -0,0 +1,60 @@
1
+ require "bmicalc/version"
2
+
3
+ class Bmicalc
4
+
5
+ CLASSIFICATIONS = {
6
+ 18.5 => 'underweight',
7
+ 25.0 => 'normal',
8
+ 30.0 => 'overweight'
9
+ }
10
+
11
+ SUB_CLASSIFICATIONS = {
12
+ 16.0 => 'severe thinness',
13
+ 17.0 => 'moderate thinness',
14
+ 18.5 => 'mild thinness',
15
+ 25.0 => 'normal',
16
+ 30.0 => 'pre-obese',
17
+ 35.0 => 'obese class I',
18
+ 40.0 => 'obese class II'
19
+ }
20
+
21
+ class MetricBMI
22
+ def calculate(weight, height)
23
+ h = height.to_f / 100
24
+ weight / (h * h)
25
+ end
26
+ end
27
+
28
+ class ImperialBMI
29
+ def calculate(weight, height)
30
+ (weight * 703) / (height * height)
31
+ end
32
+ end
33
+
34
+ def initialize(options = {})
35
+ @bmi_calculator = options.fetch(:units, :metric) == :metric ? MetricBMI.new : ImperialBMI.new
36
+ end
37
+
38
+ def calculate(weight, height)
39
+ @bmi_calculator.calculate(weight, height)
40
+ end
41
+
42
+ def classification(bmi)
43
+ find_classification(CLASSIFICATIONS, 'obese', bmi)
44
+ end
45
+
46
+ def sub_classification(bmi)
47
+ find_classification(SUB_CLASSIFICATIONS, 'obese class III', bmi)
48
+ end
49
+
50
+ private
51
+ def find_classification(classifications, default, bmi)
52
+ classifications.each do |bmi_limit, name|
53
+ if bmi < bmi_limit
54
+ return name
55
+ end
56
+ end
57
+
58
+ return default
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ class Bmicalc
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,58 @@
1
+ require 'bmicalc'
2
+
3
+ describe Bmicalc do
4
+
5
+ context 'returns bmi' do
6
+
7
+ before(:each) do
8
+ @metric_bmi = subject
9
+ @imperial_bmi = Bmicalc.new(:units => :imperial)
10
+ end
11
+
12
+ it 'underweight' do
13
+ expect(subject.calculate(54, 178)).to be_within(0.5).of(17)
14
+ expect(@metric_bmi.calculate(54, 178)).to be_within(0.05).of(@imperial_bmi.calculate(118.8, 70.078))
15
+ expect(subject.classification(18.49)).to eq('underweight')
16
+ end
17
+
18
+ it 'normal' do
19
+ expect(subject.calculate(64, 178)).to be_within(0.5).of(20)
20
+ expect(@metric_bmi.calculate(64, 178)).to be_within(0.05).of(@imperial_bmi.calculate(140.8, 70.078))
21
+ expect(subject.classification(18.50)).to eq('normal')
22
+ expect(subject.classification(24.99)).to eq('normal')
23
+ end
24
+
25
+ it 'overweight' do
26
+ expect(subject.calculate(68, 148)).to be_within(0.5).of(31)
27
+ expect(@metric_bmi.calculate(68, 178)).to be_within(0.05).of(@imperial_bmi.calculate(149.6, 70.078))
28
+ expect(subject.classification(25)).to eq('overweight')
29
+ expect(subject.classification(29.99)).to eq('overweight')
30
+ end
31
+
32
+ it 'obese' do
33
+ expect(subject.calculate(118, 168)).to be_within(0.5).of(42)
34
+ expect(@metric_bmi.calculate(118, 168)).to be_within(0.1).of(@imperial_bmi.calculate(259.6, 66.1417))
35
+ expect(subject.classification(30)).to eq('obese')
36
+ end
37
+
38
+ it 'should have sub classifications' do
39
+ expect(subject.sub_classification(15.99)).to eq('severe thinness')
40
+ expect(subject.sub_classification(16.99)).to eq('moderate thinness')
41
+ expect(subject.sub_classification(18.49)).to eq('mild thinness')
42
+ expect(subject.sub_classification(24.99)).to eq('normal')
43
+ expect(subject.sub_classification(29.99)).to eq('pre-obese')
44
+ expect(subject.sub_classification(34.99)).to eq('obese class I')
45
+ expect(subject.sub_classification(39.99)).to eq('obese class II')
46
+ expect(subject.sub_classification(40)).to eq('obese class III')
47
+ end
48
+ end
49
+
50
+ it 'default to metric' do
51
+ expect(subject.calculate(64, 178)).to eq(20.199469763918696)
52
+ end
53
+
54
+ it 'imperial' do
55
+ bmi = Bmicalc.new(:units => :imperial)
56
+ expect(bmi.calculate(141, 70.1)).to eq(20.171509622487545)
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bmicalc-qwertme
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric di Domenico
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Calculate BMI
56
+ email:
57
+ - eric@didomenico.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rvmrc"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bmicalc.gemspec
70
+ - lib/bmicalc.rb
71
+ - lib/bmicalc/version.rb
72
+ - spec/bmicalc_spec.rb
73
+ homepage: https://github.com/qwertme/bmicalc.git
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Calculate BMI
97
+ test_files:
98
+ - spec/bmicalc_spec.rb