ski_binding_calculator 0.6.1 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,8 +22,7 @@ class SkiBinding::Calculator
22
22
  hashy[:shoe_size] = attrs[:shoe_size].to_f || attrs["shoe_size"].to_f
23
23
  hashy[:birthday] = attrs[:birthday] || attrs["birthdate"]
24
24
  hashy[:type] = attrs[:type] || attrs["type"]
25
- attrs = hashy
26
- attrs
25
+ hashy
27
26
  end
28
27
 
29
28
  def self.age(attrs)
@@ -82,7 +81,7 @@ class SkiBinding::Calculator
82
81
  settings.each do |s|
83
82
  if s.shoe_size_range.include?(attrs[:shoe_size])
84
83
  unless s.z_value.nil?
85
- return {"z_value" => s.z_value}
84
+ return {:z_value => s.z_value}
86
85
  else
87
86
  raise ArgumentError, "Please calculate z-index by hand."
88
87
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'ski_binding_calculator'
4
- s.version = '0.6.1'
4
+ s.version = '0.6.5'
5
5
  s.summary = "Ski Binding Calculator"
6
6
  s.description = "Calculates the z-value according to ISO 11088."
7
7
  s.authors = ["Jonas Ruef, Felix Langenegger"]
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.add_development_dependency "spork", "~> 0.9.2"
14
14
  s.add_development_dependency "simplecov", "~> 0.7.1"
15
15
  s.add_development_dependency "timecop", "~> 0.6.3"
16
+ s.add_development_dependency "fuubar", "~> 1.1.1"
16
17
 
17
18
  s.files = Dir.glob("{config,lib,spec}/**/*")
18
19
  s.files += %w(Rakefile ski_binding_calculator.gemspec)
@@ -1,144 +1,170 @@
1
1
  require 'spec_helper'
2
2
  require 'timecop'
3
3
 
4
+ # The scenario: according to table B.1 in ISO 11088 a skier which is
5
+ # type 2, 70 kg of weight, 170cm of height, has a sole length of
6
+ # 315mm, and is born 01/01/1983 has code "L" or in our notation 11
7
+ # (see readme for details on codes). Furthermore it's z_value is 6.
4
8
  describe SkiBinding::Calculator do
9
+ subject(:skiers_parameters) do
10
+ { :type => "Type2",
11
+ :weight => "70",
12
+ :height => "170",
13
+ :shoe_size => "315",
14
+ :birthday => "1983-01-01" }
15
+ end
16
+ subject(:expected_preped) do
17
+ { :type => "Type2",
18
+ :weight => 70.0,
19
+ :height => 170.0,
20
+ :shoe_size => 315.0,
21
+ :birthday => "1983-01-01" }
22
+ end
23
+ subject(:expected_aged) do
24
+ { :type => "Type2",
25
+ :weight => 70.0,
26
+ :height => 170.0,
27
+ :shoe_size => 315.0,
28
+ :age => 30 }
29
+ end
30
+ subject(:expected_validated) do
31
+ { :type => 1,
32
+ :weight => 70.0,
33
+ :height => 170.0,
34
+ :shoe_size => 315.0,
35
+ :age => 30 }
36
+ end
37
+ subject(:expected_code) { 11 }
38
+ subject(:expected_setting) do
39
+ { :z_value => 6 }
40
+ end
41
+
5
42
  before(:all) do
6
- @hash = {:type => "Type2",
7
- :weight => "70",
8
- :height => "170",
9
- :shoe_size => "315",
10
- :birthday => "1983-01-01"}
11
- #We freeze time so birthday will always be 30 years back
43
+ #freeze time! so birthday will always be 30 years back
12
44
  Timecop.freeze(2013, 8, 13)
13
45
  end
14
46
 
15
47
  describe "#new" do
16
- it "returns a BindingCalculator class" do
17
- SkiBinding::Calculator.new.class.should == SkiBinding::Calculator
18
- end
48
+ it { SkiBinding::Calculator.new.class.should == SkiBinding::Calculator }
19
49
  end
20
50
 
21
51
  describe "#prep_attributes" do
22
- it "returns a valid hash" do
23
- expected_hash = {:type => "Type2",
24
- :weight => 70.0,
25
- :height => 170.0,
26
- :shoe_size => 315.0,
27
- :birthday => "1983-01-01"}
28
- SkiBinding::Calculator.prep_attributes(@hash).should == expected_hash
29
- end
52
+ subject(:calculated_preped) { SkiBinding::Calculator.prep_attributes(parameters) }
53
+ let(:parameters) { skiers_parameters }
54
+
55
+ it { calculated_preped.should == expected_preped }
30
56
 
31
- it "returns argument error if weight < 10kg" do
32
- @hash[:weight] = "9"
33
- expect { SkiBinding::Calculator.prep_attributes(@hash) }
34
- .to raise_error(ArgumentError, "Weight must be at least 10kg")
35
- @hash[:weight] = "70"
57
+ context "when weight < 10kg" do
58
+ let(:parameters) do
59
+ skiers_parameters[:weight] = 9
60
+ skiers_parameters
61
+ end
62
+ it { expect { calculated_preped }
63
+ .to raise_error(ArgumentError, "Weight must be at least 10kg") }
36
64
  end
37
65
  end
38
66
 
39
67
  describe "#age" do
40
- before(:all) do
41
- @preped_hash = SkiBinding::Calculator.prep_attributes(@hash)
42
- end
68
+ subject(:calculated_aged) { SkiBinding::Calculator.age(preped) }
69
+ let(:preped) { expected_preped }
43
70
 
44
- it "returns a hash with an age" do
45
- result = SkiBinding::Calculator.age(@preped_hash)
46
- result[:age].should == 30
47
- end
71
+ it { calculated_aged.should == expected_aged }
48
72
  end
49
73
 
50
74
  describe "#validate_type" do
51
- before :all do
52
- preped_hash = SkiBinding::Calculator.prep_attributes(@hash)
53
- @aged_hash = SkiBinding::Calculator.age(preped_hash)
54
- end
75
+ subject(:calculated_validated) { SkiBinding::Calculator.validate_type(aged) }
76
+ let(:aged) { expected_aged }
55
77
 
56
78
  it "sets \"Type2\" to 1" do
57
- result = SkiBinding::Calculator.validate_type(@aged_hash)
58
- result[:type].should == 1
79
+ calculated_validated.should == expected_validated
59
80
  end
60
81
 
61
- it "raises argument error on type \"unknown\"" do
62
- wrong_aged_hash = {:type => "unknown",
63
- :weight => 70,
64
- :height => 170,
65
- :shoe_size => 315,
66
- :age => 30}
67
- expect { SkiBinding::Calculator.validate_type(wrong_aged_hash) }
68
- .to raise_error(ArgumentError, "You have entered an invalid type.")
82
+ context "when type is \"unknown\"" do
83
+ let(:aged) do
84
+ expected_aged[:type] = "unknown"
85
+ expected_aged
86
+ end
87
+
88
+ it{ expect { calculated_validated }
89
+ .to raise_error(ArgumentError, "You have entered an invalid type.") }
69
90
  end
70
91
  end
71
92
 
72
-
73
93
  describe "#binding_code" do
74
- before :each do
75
- preped_hash = SkiBinding::Calculator.prep_attributes(@hash)
76
- aged_hash = SkiBinding::Calculator.age(preped_hash)
77
- @type_validated_hash = SkiBinding::Calculator.validate_type(aged_hash)
78
- end
94
+ subject(:calculated_code) { SkiBinding::Calculator.binding_code(validated) }
95
+ let(:validated) { expected_validated }
79
96
 
80
- it "returns a valid code" do
81
- SkiBinding::Calculator.binding_code(@type_validated_hash).should == 11
82
- end
97
+ it{ calculated_code.should == 11 }
83
98
 
84
- it "returns unchanged code if weight less than 13kg" do
85
- # because we set "Type2" the code would be changed by 1
86
- @type_validated_hash[:weight] = 12
87
- SkiBinding::Calculator.binding_code(@type_validated_hash).should == 0
99
+ context "when weight < 13kg" do
100
+ let(:validated) do
101
+ expected_validated[:weight] = 12
102
+ expected_validated
103
+ end
104
+ #because "Type 2" is given the code would be changed to 1
105
+ it{ calculated_code.should == 0 }
88
106
  end
89
107
 
90
- it "raises argumentError if no code was found" do
91
- @type_validated_hash[:weight] = -1
92
- @type_validated_hash[:height] = -1
93
- expect { SkiBinding::Calculator.binding_code(@type_validated_hash) }
94
- .to raise_error(ArgumentError, "You have entered invalid weight and/or height")
108
+ context "when no code found" do
109
+ let(:validated) do
110
+ expected_validated[:weight] = -1
111
+ expected_validated[:height] = -1
112
+ expected_validated
113
+ end
114
+
115
+ it { expect { calculated_code }.
116
+ to raise_error(ArgumentError, "You have entered invalid weight and/or height") }
95
117
  end
96
118
 
97
- context "returns code one less if age >= 50 || age < 10" do
98
- before :each do
99
- preped_hash = SkiBinding::Calculator.prep_attributes(@hash)
100
- aged_hash = SkiBinding::Calculator.age(preped_hash)
101
- @type_validated_hash_age_context = SkiBinding::Calculator.validate_type(aged_hash)
102
- @code = SkiBinding::Calculator.binding_code(@type_validated_hash_age_context)
119
+ context "when age >= 50 || age < 10" do
120
+ context "age is 50" do
121
+ let(:validated) do
122
+ expected_validated[:age] = 50
123
+ expected_validated
124
+ end
125
+
126
+ it { calculated_code.should == (expected_code - 1) }
103
127
  end
104
128
 
105
- it "age is 50" do
106
- @type_validated_hash_age_context[:age] = 50
107
- lambda { @code = SkiBinding::Calculator.binding_code(@type_validated_hash_age_context) }
108
- .should change{@code}.by(-1)
129
+ context "age is 51" do
130
+ let(:validated) do
131
+ expected_validated[:age] = 51
132
+ expected_validated
133
+ end
134
+
135
+ it { calculated_code.should == (expected_code - 1) }
109
136
  end
110
137
 
111
- it "age is 51" do
112
- @type_validated_hash_age_context[:age] = 51
113
- lambda { @code = SkiBinding::Calculator.binding_code(@type_validated_hash_age_context) }
114
- .should change{@code}.by(-1)
138
+ context "age is 9" do
139
+ let(:validated) do
140
+ expected_validated[:age] = 9
141
+ expected_validated
142
+ end
143
+
144
+ it { calculated_code.should == (expected_code - 1) }
115
145
  end
116
146
  end
117
147
  end
118
-
148
+
119
149
  describe "#binding_setting" do
120
- before :each do
121
- preped_hash = SkiBinding::Calculator.prep_attributes(@hash)
122
- aged_hash = SkiBinding::Calculator.age(preped_hash)
123
- @type_validated_hash = SkiBinding::Calculator.validate_type(aged_hash)
124
- end
150
+ subject(:calculated_setting) { SkiBinding::Calculator.binding_setting(validated, binding_code) }
151
+ let(:binding_code) { expected_code }
152
+ let(:validated) { expected_validated }
125
153
 
126
- it "returns a valid setting" do
127
- SkiBinding::Calculator.binding_setting(@type_validated_hash, 11).should ==
128
- {"z_value"=>6}
129
- end
154
+ it{ calculated_setting.should == expected_setting }
130
155
 
131
- it "raises argument error if no settings found" do
132
- expect { SkiBinding::Calculator.binding_setting(@type_validated_hash, 0) }
133
- .to raise_error(ArgumentError, "Please calculate z-index by hand.")
156
+ context "when no setting found" do
157
+ let(:binding_code) { 0 }
158
+ it{ expect { calculated_setting }
159
+ .to raise_error(ArgumentError, "Please calculate z-index by hand.") }
134
160
  end
135
161
  end
136
-
162
+
137
163
  describe "#setting" do
138
- it "returns a valid setting" do
139
- SkiBinding::Calculator.setting(@hash).should ==
140
- {"z_value"=>6}
141
- end
164
+ subject(:all_at_once_calculated) { SkiBinding::Calculator.setting(parameters) }
165
+ let(:parameters) { skiers_parameters }
166
+
167
+ it{ all_at_once_calculated.should == expected_setting }
142
168
  end
143
169
 
144
170
  after(:all) do
@@ -7,18 +7,9 @@ describe SkiBinding::Code do
7
7
  end
8
8
  end
9
9
 
10
- context "instantiated Code class" do
11
- before :all do
12
- @code = SkiBinding::Code.new
13
- end
14
-
15
- it "has attribute weight" do
16
- @code.should respond_to :weight
17
- end
18
-
19
- it "has attribute heigth" do
20
- @code.should respond_to :height
21
- end
10
+ context "when instantiated Code class" do
11
+ it { should respond_to :weight }
12
+ it { should respond_to :height }
22
13
  end
23
14
  end
24
15
 
@@ -1,69 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
+ # For original table with codes referred to in this tests see iso 11088
4
+ # Table B.1
3
5
  describe "ConfigLoader" do
4
-
5
- before(:all) do
6
- @range = 0..15 #cause 16 settings
7
- @dummy_class = DummyClass.new
8
- @dummy_class.extend(SkiBinding::ConfigLoader)
9
- end
6
+ subject(:dummy_class) { DummyClass.new.extend(SkiBinding::ConfigLoader) }
10
7
 
11
8
  describe "loading binding codes:" do
12
- it "something gets loaded" do
13
- @dummy_class.load_binding_codes.class.should_not == nil
14
- end
9
+ it { dummy_class.load_binding_codes.class.should_not == nil }
15
10
 
16
- context "loaded codes" do
17
- before :all do
18
- @codes = @dummy_class.load_binding_codes
19
- end
20
-
21
- it "is array" do
22
- @codes.class.should == Array
23
- end
11
+ context "when loaded codes" do
12
+ subject(:codes) { dummy_class.load_binding_codes }
24
13
 
25
- it "first element is code" do
26
- @codes[0].class.should == SkiBinding::Code
27
- end
28
-
29
- it "has 15 codes" do
30
- @codes.size.should == 13
31
- end
14
+ it{ codes.class.should == Array }
15
+ it{ codes[0].class.should == SkiBinding::Code }
16
+ it{ codes.size.should == 13 }
32
17
  end
33
18
  end
34
19
 
35
20
  describe "loading binding settings for all codes" do
36
- it "something gets loaded" do
37
- @range.each do |index|
38
- @dummy_class.load_binding_settings(index).class.should_not == nil
39
- end
21
+ subject(:settings_all_codes) do
22
+ settings = []
23
+ (0..15).each { |i| settings << dummy_class.load_binding_settings(i) }
24
+ settings
40
25
  end
41
26
 
42
- context "loaded settings for each code" do
43
- before :all do
44
- @settings_all_codes = []
45
- @range.each do |index|
46
- @settings_all_codes << @dummy_class.load_binding_settings(index)
47
- end
48
- end
49
-
50
- it "is array" do
51
- @settings_all_codes.each do |s|
52
- s.class.should == Array
53
- end
54
- end
55
-
56
- it "first element is setting" do
57
- @settings_all_codes.each do |s|
58
- s[0].class.should == SkiBinding::Setting
59
- end
60
- end
61
-
62
- it "has 6 settings" do
63
- @settings_all_codes.each do |s|
64
- s.size.should == 8
65
- end
66
- end
27
+ context "for each code" do
28
+ it { settings_all_codes.each { |s| s.class.should == Array } }
29
+ it { settings_all_codes.each { |s| s[0].class.should == SkiBinding::Setting } }
30
+ it { settings_all_codes.each { |s| s.size.should == 8 } }
67
31
  end
68
32
  end
69
33
  end
@@ -7,25 +7,10 @@ describe SkiBinding::Setting do
7
7
  end
8
8
  end
9
9
 
10
- context "instantiated Setting class" do
11
- before :all do
12
- @setting = SkiBinding::Setting.new
13
- end
14
-
15
- it "has attribute shoe_size_range" do
16
- @setting.should respond_to :shoe_size_range
17
- end
18
-
19
- it "has attribute z_value" do
20
- @setting.should respond_to :z_value
21
- end
22
-
23
- it "has attribute twist" do
24
- @setting.should respond_to :twist
25
- end
26
-
27
- it "has attribute forward_lean" do
28
- @setting.should respond_to :forward_lean
29
- end
10
+ context "when instantiated Setting class" do
11
+ it { should respond_to :shoe_size_range }
12
+ it { should respond_to :z_value }
13
+ it { should respond_to :twist }
14
+ it { should respond_to :forward_lean }
30
15
  end
31
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ski_binding_calculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-13 00:00:00.000000000 Z
12
+ date: 2013-08-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -75,6 +75,22 @@ dependencies:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: 0.6.3
78
+ - !ruby/object:Gem::Dependency
79
+ name: fuubar
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.1.1
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.1.1
78
94
  description: Calculates the z-value according to ISO 11088.
79
95
  email: support@fadendaten.ch
80
96
  executables: []