nemah 0.1.1

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 (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/Guardfile +6 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +44 -0
  9. data/Rakefile +6 -0
  10. data/lib/nemah.rb +2 -0
  11. data/lib/nemah/horse.rb +80 -0
  12. data/lib/nemah/need.rb +41 -0
  13. data/lib/nemah/specific_need/abstract_need.rb +49 -0
  14. data/lib/nemah/specific_need/calcium.rb +13 -0
  15. data/lib/nemah/specific_need/energy.rb +63 -0
  16. data/lib/nemah/specific_need/magnesium.rb +13 -0
  17. data/lib/nemah/specific_need/mineral_behaviour.rb +77 -0
  18. data/lib/nemah/specific_need/phosphor.rb +13 -0
  19. data/lib/nemah/specific_need/protein.rb +23 -0
  20. data/lib/nemah/specific_need/salt.rb +13 -0
  21. data/lib/nemah/specific_need/selenium.rb +23 -0
  22. data/lib/nemah/specific_need/solids.rb +27 -0
  23. data/lib/nemah/version.rb +3 -0
  24. data/lib/nemah/workload.rb +30 -0
  25. data/nemah.gemspec +27 -0
  26. data/spec/nemah/horse_spec.rb +93 -0
  27. data/spec/nemah/need_spec.rb +103 -0
  28. data/spec/nemah/specific_need/calcium_spec.rb +15 -0
  29. data/spec/nemah/specific_need/energy_spec.rb +76 -0
  30. data/spec/nemah/specific_need/magnesium_spec.rb +15 -0
  31. data/spec/nemah/specific_need/phosphor_spec.rb +15 -0
  32. data/spec/nemah/specific_need/protein_spec.rb +55 -0
  33. data/spec/nemah/specific_need/salt_spec.rb +15 -0
  34. data/spec/nemah/specific_need/selenium_spec.rb +57 -0
  35. data/spec/nemah/specific_need/solids_spec.rb +57 -0
  36. data/spec/nemah/workload_spec.rb +35 -0
  37. data/spec/spec_helper.rb +4 -0
  38. data/spec/support/shared_examples_for_a_mineral.rb +73 -0
  39. data/spec/support/shared_examples_for_a_specific_need.rb +12 -0
  40. metadata +182 -0
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Nemah::SpecificNeed::Magnesium do
4
+ it_behaves_like 'a specific need' do
5
+ let(:unit) { :g }
6
+ end
7
+
8
+ it_behaves_like 'a mineral' do
9
+ let(:no_workload_min_need) { 7.95 }
10
+ let(:light_workload_min_need) { 10.07 }
11
+ let(:medium_workload_min_need) { 12.19 }
12
+ let(:hard_workload_min_need) { 15.9 }
13
+ let(:very_hard_workload_min_need) { 15.9 }
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Nemah::SpecificNeed::Phosphor do
4
+ it_behaves_like 'a specific need' do
5
+ let(:unit) { :g }
6
+ end
7
+
8
+ it_behaves_like 'a mineral' do
9
+ let(:no_workload_min_need) { 14.84 }
10
+ let(:light_workload_min_need) { 19.08 }
11
+ let(:medium_workload_min_need) { 22.26 }
12
+ let(:hard_workload_min_need) { 30.74 }
13
+ let(:very_hard_workload_min_need) { 30.74 }
14
+ end
15
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Nemah::SpecificNeed::Protein do
4
+ it_behaves_like 'a specific need' do
5
+ let(:unit) { :g }
6
+ end
7
+
8
+ describe '#to_rounded_range' do
9
+ it 'returns a range between minimum and maximum allowed amounts, rounded to two decimals' do
10
+ expect(protein.to_rounded_range).to eq(288.63..352.77)
11
+ end
12
+
13
+ it 'optionally takes the number of decimals' do
14
+ expect(protein.to_rounded_range(decimals: 0)).to eq(289..353)
15
+ end
16
+ end
17
+
18
+ describe '#ideal' do
19
+ it 'returns the ideal amount of protein needed' do
20
+ expect(protein.ideal).to eq(320.70)
21
+ end
22
+
23
+ it 'optionally takes the number of decimals' do
24
+ expect(protein.ideal(decimals: 0)).to eq(321)
25
+ end
26
+ end
27
+
28
+ describe '#min' do
29
+ it 'returns the minimum protein need' do
30
+ expect(protein.min).to eq(288.63)
31
+ end
32
+
33
+ it 'optionally takes the number of decimals' do
34
+ expect(protein.min(decimals: 1)).to eq(288.6)
35
+ end
36
+ end
37
+
38
+ describe '#max' do
39
+ it 'returns the maximum protein need' do
40
+ expect(protein.max).to eq(352.77)
41
+ end
42
+
43
+ it 'optionally takes the number of decimals' do
44
+ expect(protein.max(decimals: 1)).to eq(352.8)
45
+ end
46
+ end
47
+
48
+ def protein
49
+ Nemah::SpecificNeed::Protein.new(need)
50
+ end
51
+
52
+ def need
53
+ double(:energy => double(:ideal => 53.45))
54
+ end
55
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Nemah::SpecificNeed::Salt do
4
+ it_behaves_like 'a specific need' do
5
+ let(:unit) { :g }
6
+ end
7
+
8
+ it_behaves_like 'a mineral' do
9
+ let(:no_workload_min_need) { 27.03 }
10
+ let(:light_workload_min_need) { 37.10 }
11
+ let(:medium_workload_min_need) { 47.70 }
12
+ let(:hard_workload_min_need) { 47.70 }
13
+ let(:very_hard_workload_min_need) { 68.90 }
14
+ end
15
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Nemah::SpecificNeed::Selenium do
4
+ it_behaves_like 'a specific need' do
5
+ let(:unit) { :mg }
6
+ end
7
+
8
+ describe '#to_rounded_range' do
9
+ it 'returns a range between minimum and maximum allowed amounts, rounded to two decimals' do
10
+ expect(selenium.to_rounded_range).to eq(1.06..26.50)
11
+ end
12
+
13
+ it 'optionally takes the number of decimals' do
14
+ expect(selenium.to_rounded_range(decimals: 1)).to eq(1.1..26.5)
15
+ end
16
+ end
17
+
18
+ describe '#ideal' do
19
+ it 'returns the ideal amount of selenium needed' do
20
+ expect(selenium.ideal).to eq(1.06)
21
+ end
22
+
23
+ it 'optionally takes the number of decimals' do
24
+ expect(selenium.ideal(decimals: 1)).to eq(1.1)
25
+ end
26
+ end
27
+
28
+ describe '#min' do
29
+ it 'returns the minimum selenium need' do
30
+ expect(selenium.min).to eq(1.06)
31
+ end
32
+
33
+ it 'optionally takes the number of decimals' do
34
+ expect(selenium.min(decimals: 1)).to eq(1.1)
35
+ end
36
+ end
37
+
38
+ describe '#max' do
39
+ it 'returns the maximum selenium need' do
40
+ expect(selenium.max).to eq(26.50)
41
+ end
42
+
43
+ it 'optionally takes the number of decimals' do
44
+ expect(selenium.max(decimals: 0)).to eq(27)
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def selenium
51
+ Nemah::SpecificNeed::Selenium.new(need)
52
+ end
53
+
54
+ def need
55
+ double(:horse => double(:weight_in_deciton => 5.3))
56
+ end
57
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe Nemah::SpecificNeed::Solids do
4
+ it_behaves_like 'a specific need' do
5
+ let(:unit) { :kg }
6
+ end
7
+
8
+ describe '#to_rounded_range' do
9
+ it 'returns a range between minimum and maximum allowed amounts, rounded to two decimals' do
10
+ expect(solids.to_rounded_range).to eq(7.65..Float::INFINITY)
11
+ end
12
+
13
+ it 'optionally takes the number of decimals' do
14
+ expect(solids.to_rounded_range(decimals: 0)).to eq(8..Float::INFINITY)
15
+ end
16
+ end
17
+
18
+ describe '#ideal' do
19
+ it 'returns the ideal amount of solids needed' do
20
+ expect(solids.ideal).to eq(7.65)
21
+ end
22
+
23
+ it 'optionally takes the number of decimals' do
24
+ expect(solids.ideal(decimals: 1)).to eq(7.7)
25
+ end
26
+ end
27
+
28
+ describe '#min' do
29
+ it 'returns the minimum solids need' do
30
+ expect(solids.min).to eq(7.65)
31
+ end
32
+
33
+ it 'optionally takes the number of decimals' do
34
+ expect(solids.min(decimals: 1)).to eq(7.7)
35
+ end
36
+ end
37
+
38
+ describe '#max' do
39
+ it 'returns the maximum solids need' do
40
+ expect(solids.max).to eq(Float::INFINITY)
41
+ end
42
+
43
+ it 'optionally takes the number of decimals' do
44
+ expect(solids.max(decimals: 10)).to eq(Float::INFINITY)
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def solids
51
+ Nemah::SpecificNeed::Solids.new(need)
52
+ end
53
+
54
+ def need
55
+ double(:horse => double(:weight_in_deciton => 5.1))
56
+ end
57
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Nemah::Workload do
4
+ it 'can have the amount of walking set' do
5
+ expect(workload_with(walk: 30).walk).to eq(30)
6
+ end
7
+
8
+ it 'can have the amount of trot and canter set' do
9
+ expect(workload_with(trot_and_canter: 5).trot_and_canter).to eq(5)
10
+ end
11
+
12
+ it 'can have the number of days of exercise per week set' do
13
+ expect(workload_with(days_per_week: 3).days_per_week).to eq(3)
14
+ end
15
+
16
+ it 'does not allow days_per_week to be greater than 7' do
17
+ expect { workload_with(days_per_week: 10) }.to raise_error(ArgumentError, 'days_per_week must be between 0 and 7')
18
+ end
19
+
20
+ it 'does not allow days_per_week to be less than 0' do
21
+ expect { workload_with(days_per_week: -2) }.to raise_error(ArgumentError, 'days_per_week must be between 0 and 7')
22
+ end
23
+
24
+ it 'is equal to another workload with the same amount of work' do
25
+ workload = workload_with(walk: 30, trot_and_canter: 5, days_per_week: 3)
26
+ another_workload = workload_with(walk: 30, trot_and_canter: 5, days_per_week: 3)
27
+ expect(workload).to eq(another_workload)
28
+ end
29
+
30
+ private
31
+
32
+ def workload_with(args)
33
+ Nemah::Workload.new(args)
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'nemah'
3
+ Dir['./spec/support/**/*.rb'].sort.each { |file| require file }
4
+ require 'byebug'
@@ -0,0 +1,73 @@
1
+ shared_examples_for 'a mineral' do
2
+ describe '#to_rounded_range' do
3
+ it 'returns a range between minimum and maximum allowed amounts, rounded to two decimals' do
4
+ expect(mineral.to_rounded_range).to eq(no_workload_min_need..Float::INFINITY)
5
+ end
6
+
7
+ it 'optionally takes the number of decimals' do
8
+ expect(mineral.to_rounded_range(decimals: 0)).to eq(no_workload_min_need.round(0)..Float::INFINITY)
9
+ end
10
+
11
+ context 'with a workload' do
12
+ it 'adjusts for a light workload' do
13
+ mineral = mineral_for_horse_with_workload_energy_need(10.0)
14
+ expect(mineral.to_rounded_range).to eq(light_workload_min_need..Float::INFINITY)
15
+ end
16
+
17
+ it 'adjusts for a medium workload' do
18
+ mineral = mineral_for_horse_with_workload_energy_need(12.0)
19
+ expect(mineral.to_rounded_range).to eq(medium_workload_min_need..Float::INFINITY)
20
+ end
21
+
22
+ it 'adjusts for a hard workload' do
23
+ mineral = mineral_for_horse_with_workload_energy_need(20.0)
24
+ expect(mineral.to_rounded_range).to eq(hard_workload_min_need..Float::INFINITY)
25
+ end
26
+
27
+ it 'adjusts for a very hard workload' do
28
+ mineral = mineral_for_horse_with_workload_energy_need(30.0)
29
+ expect(mineral.to_rounded_range).to eq(very_hard_workload_min_need..Float::INFINITY)
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '#ideal' do
35
+ it 'returns the ideal need' do
36
+ expect(mineral.ideal).to eq(no_workload_min_need)
37
+ end
38
+
39
+ it 'optionally takes the number of decimals' do
40
+ expect(mineral.ideal(decimals: 1)).to eq(no_workload_min_need.round(1))
41
+ end
42
+ end
43
+
44
+ describe '#min' do
45
+ it 'returns the minimum need' do
46
+ expect(mineral.min).to eq(no_workload_min_need)
47
+ end
48
+
49
+ it 'optionally takes the number of decimals' do
50
+ expect(mineral.min(decimals: 0)).to eq(no_workload_min_need.round(0))
51
+ end
52
+ end
53
+
54
+ describe '#max' do
55
+ it 'returns the maximum need' do
56
+ expect(mineral.max).to eq(Float::INFINITY)
57
+ end
58
+
59
+ it 'optionally takes the number of decimals' do
60
+ expect(mineral.max(decimals: 0)).to eq(Float::INFINITY)
61
+ end
62
+ end
63
+
64
+ def mineral
65
+ mineral_for_horse_with_workload_energy_need(0.0)
66
+ end
67
+
68
+ def mineral_for_horse_with_workload_energy_need(workload)
69
+ workload_energy_need = double('energy', :for_maintenance => 40.0, :for_workload => workload)
70
+ fake_need = double('need', :horse => double(:weight_in_deciton => 5.3), :energy => workload_energy_need)
71
+ described_class.new(fake_need)
72
+ end
73
+ end
@@ -0,0 +1,12 @@
1
+ shared_examples_for 'a specific need' do
2
+ subject(:need) { described_class.new(double('need for a horse')) }
3
+
4
+ describe 'the common interface' do
5
+ it { should respond_to(:to_rounded_range) }
6
+ it { should respond_to(:ideal) }
7
+ it { should respond_to(:min) }
8
+ it { should respond_to(:max) }
9
+ end
10
+
11
+ specify { expect(need.unit).to eq unit }
12
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nemah
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kim Persson
8
+ - Lennart Fridén
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: byebug
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.5'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.5'
42
+ - !ruby/object:Gem::Dependency
43
+ name: guard
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.2'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.2'
56
+ - !ruby/object:Gem::Dependency
57
+ name: guard-rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '4.2'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '4.2'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.1'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.1'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '2.14'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '2.14'
98
+ description: Nemah is a library for calculating the proper amount of fodder for your
99
+ horse.
100
+ email:
101
+ - forgetmenotox@notingham.se
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - Guardfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - lib/nemah.rb
115
+ - lib/nemah/horse.rb
116
+ - lib/nemah/need.rb
117
+ - lib/nemah/specific_need/abstract_need.rb
118
+ - lib/nemah/specific_need/calcium.rb
119
+ - lib/nemah/specific_need/energy.rb
120
+ - lib/nemah/specific_need/magnesium.rb
121
+ - lib/nemah/specific_need/mineral_behaviour.rb
122
+ - lib/nemah/specific_need/phosphor.rb
123
+ - lib/nemah/specific_need/protein.rb
124
+ - lib/nemah/specific_need/salt.rb
125
+ - lib/nemah/specific_need/selenium.rb
126
+ - lib/nemah/specific_need/solids.rb
127
+ - lib/nemah/version.rb
128
+ - lib/nemah/workload.rb
129
+ - nemah.gemspec
130
+ - spec/nemah/horse_spec.rb
131
+ - spec/nemah/need_spec.rb
132
+ - spec/nemah/specific_need/calcium_spec.rb
133
+ - spec/nemah/specific_need/energy_spec.rb
134
+ - spec/nemah/specific_need/magnesium_spec.rb
135
+ - spec/nemah/specific_need/phosphor_spec.rb
136
+ - spec/nemah/specific_need/protein_spec.rb
137
+ - spec/nemah/specific_need/salt_spec.rb
138
+ - spec/nemah/specific_need/selenium_spec.rb
139
+ - spec/nemah/specific_need/solids_spec.rb
140
+ - spec/nemah/workload_spec.rb
141
+ - spec/spec_helper.rb
142
+ - spec/support/shared_examples_for_a_mineral.rb
143
+ - spec/support/shared_examples_for_a_specific_need.rb
144
+ homepage: https://github.com/Lavinia/Nemah
145
+ licenses:
146
+ - MIT
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.2.0
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: Horse fodder calculations library.
168
+ test_files:
169
+ - spec/nemah/horse_spec.rb
170
+ - spec/nemah/need_spec.rb
171
+ - spec/nemah/specific_need/calcium_spec.rb
172
+ - spec/nemah/specific_need/energy_spec.rb
173
+ - spec/nemah/specific_need/magnesium_spec.rb
174
+ - spec/nemah/specific_need/phosphor_spec.rb
175
+ - spec/nemah/specific_need/protein_spec.rb
176
+ - spec/nemah/specific_need/salt_spec.rb
177
+ - spec/nemah/specific_need/selenium_spec.rb
178
+ - spec/nemah/specific_need/solids_spec.rb
179
+ - spec/nemah/workload_spec.rb
180
+ - spec/spec_helper.rb
181
+ - spec/support/shared_examples_for_a_mineral.rb
182
+ - spec/support/shared_examples_for_a_specific_need.rb