ski_binding_calculator 0.0.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ - !ruby/object:SkiBinding::Code
2
+ weight: !ruby/range 10..13
3
+ height: !ruby/range 1..148
4
+ - !ruby/object:SkiBinding::Code
5
+ weight: !ruby/range 14..17
6
+ height: !ruby/range 1..148
7
+ - !ruby/object:SkiBinding::Code
8
+ weight: !ruby/range 18..21
9
+ height: !ruby/range 1..148
10
+ - !ruby/object:SkiBinding::Code
11
+ weight: !ruby/range 22..25
12
+ height: !ruby/range 1..148
13
+ - !ruby/object:SkiBinding::Code
14
+ weight: !ruby/range 26..30
15
+ height: !ruby/range 1..148
16
+ - !ruby/object:SkiBinding::Code
17
+ weight: !ruby/range 31..35
18
+ height: !ruby/range 1..148
19
+ - !ruby/object:SkiBinding::Code
20
+ weight: !ruby/range 36..41
21
+ height: !ruby/range 1..148
22
+ - !ruby/object:SkiBinding::Code
23
+ weight: !ruby/range 42..48
24
+ height: !ruby/range 1..148
25
+ - !ruby/object:SkiBinding::Code
26
+ weight: !ruby/range 49..57
27
+ height: !ruby/range 149..157
28
+ - !ruby/object:SkiBinding::Code
29
+ weight: !ruby/range 58..66
30
+ height: !ruby/range 158..166
31
+ - !ruby/object:SkiBinding::Code
32
+ weight: !ruby/range 67..78
33
+ height: !ruby/range 167..178
34
+ - !ruby/object:SkiBinding::Code
35
+ weight: !ruby/range 79..94
36
+ height: !ruby/range 179..194
37
+ - !ruby/object:SkiBinding::Code
38
+ weight: !ruby/range
39
+ begin: 1
40
+ end: .inf
41
+ height: !ruby/range
42
+ begin: 1
43
+ end: .inf
@@ -0,0 +1,485 @@
1
+ -
2
+ - !ruby/object:SkiBinding::Setting
3
+ range: !ruby/range 1..250
4
+ z_value: 0.75
5
+ turning_moment: &turning_moment 8
6
+ forward_pressure: &forward_pressure 29
7
+ - !ruby/object:SkiBinding::Setting
8
+ range: !ruby/range 251..270
9
+ z_value: 0.75
10
+ turning_moment: *turning_moment
11
+ forward_pressure: *forward_pressure
12
+ - !ruby/object:SkiBinding::Setting
13
+ range: ~
14
+ z_value: ~
15
+ turning_moment: ~
16
+ forward_pressure: ~
17
+ - !ruby/object:SkiBinding::Setting
18
+ range: ~
19
+ z_value: ~
20
+ turning_moment: ~
21
+ forward_pressure: ~
22
+ - !ruby/object:SkiBinding::Setting
23
+ range: ~
24
+ z_value: ~
25
+ turning_moment: ~
26
+ forward_pressure: ~
27
+ - !ruby/object:SkiBinding::Setting
28
+ range: ~
29
+ z_value: ~
30
+ turning_moment: ~
31
+ forward_pressure: ~
32
+ -
33
+ - !ruby/object:SkiBinding::Setting
34
+ range: !ruby/range 1..250
35
+ z_value: 1
36
+ turning_moment: &turning_moment 11
37
+ forward_pressure: &forward_pressure 40
38
+ - !ruby/object:SkiBinding::Setting
39
+ range: !ruby/range 251..270
40
+ z_value: 1
41
+ turning_moment: *turning_moment
42
+ forward_pressure: *forward_pressure
43
+ - !ruby/object:SkiBinding::Setting
44
+ range: !ruby/range 271..290
45
+ z_value: 0.75
46
+ turning_moment: *turning_moment
47
+ forward_pressure: *forward_pressure
48
+ - !ruby/object:SkiBinding::Setting
49
+ range: ~
50
+ z_value: ~
51
+ turning_moment: ~
52
+ forward_pressure: ~
53
+ - !ruby/object:SkiBinding::Setting
54
+ range: ~
55
+ z_value: ~
56
+ turning_moment: ~
57
+ forward_pressure: ~
58
+ - !ruby/object:SkiBinding::Setting
59
+ range: ~
60
+ z_value: ~
61
+ turning_moment: ~
62
+ forward_pressure: ~
63
+ -
64
+ - !ruby/object:SkiBinding::Setting
65
+ range: !ruby/range 1..250
66
+ z_value: 1.5
67
+ turning_moment: &turning_moment 14
68
+ forward_pressure: &forward_pressure 52
69
+ - !ruby/object:SkiBinding::Setting
70
+ range: !ruby/range 251..270
71
+ z_value: 1.25
72
+ turning_moment: *turning_moment
73
+ forward_pressure: *forward_pressure
74
+ - !ruby/object:SkiBinding::Setting
75
+ range: !ruby/range 271..290
76
+ z_value: 1
77
+ turning_moment: *turning_moment
78
+ forward_pressure: *forward_pressure
79
+ - !ruby/object:SkiBinding::Setting
80
+ range: ~
81
+ z_value: ~
82
+ turning_moment: ~
83
+ forward_pressure: ~
84
+ - !ruby/object:SkiBinding::Setting
85
+ range: ~
86
+ z_value: ~
87
+ turning_moment: ~
88
+ forward_pressure: ~
89
+ - !ruby/object:SkiBinding::Setting
90
+ range: ~
91
+ z_value: ~
92
+ turning_moment: ~
93
+ forward_pressure: ~
94
+ -
95
+ - !ruby/object:SkiBinding::Setting
96
+ range: !ruby/range 1..250
97
+ z_value: 1.75
98
+ turning_moment: &turning_moment 17
99
+ forward_pressure: &forward_pressure 64
100
+ - !ruby/object:SkiBinding::Setting
101
+ range: !ruby/range 251..270
102
+ z_value: 1.5
103
+ turning_moment: *turning_moment
104
+ forward_pressure: *forward_pressure
105
+ - !ruby/object:SkiBinding::Setting
106
+ range: !ruby/range 271..290
107
+ z_value: 1.5
108
+ turning_moment: *turning_moment
109
+ forward_pressure: *forward_pressure
110
+ - !ruby/object:SkiBinding::Setting
111
+ range: !ruby/range 291..310
112
+ z_value: 1.25
113
+ turning_moment: *turning_moment
114
+ forward_pressure: *forward_pressure
115
+ - !ruby/object:SkiBinding::Setting
116
+ range: ~
117
+ z_value: ~
118
+ turning_moment: ~
119
+ forward_pressure: ~
120
+ - !ruby/object:SkiBinding::Setting
121
+ range: ~
122
+ z_value: ~
123
+ turning_moment: ~
124
+ forward_pressure: ~
125
+ -
126
+ - !ruby/object:SkiBinding::Setting
127
+ range: !ruby/range 1..250
128
+ z_value: 2.25
129
+ turning_moment: &turning_moment 20
130
+ forward_pressure: &forward_pressure 75
131
+ - !ruby/object:SkiBinding::Setting
132
+ range: !ruby/range 251..270
133
+ z_value: 2
134
+ turning_moment: *turning_moment
135
+ forward_pressure: *forward_pressure
136
+ - !ruby/object:SkiBinding::Setting
137
+ range: !ruby/range 271..290
138
+ z_value: 1.75
139
+ turning_moment: *turning_moment
140
+ forward_pressure: *forward_pressure
141
+ - !ruby/object:SkiBinding::Setting
142
+ range: !ruby/range 291..310
143
+ z_value: 1.5
144
+ turning_moment: *turning_moment
145
+ forward_pressure: *forward_pressure
146
+ - !ruby/object:SkiBinding::Setting
147
+ range: !ruby/range 311..330
148
+ z_value: 1.5
149
+ turning_moment: *turning_moment
150
+ forward_pressure: *forward_pressure
151
+ - !ruby/object:SkiBinding::Setting
152
+ range: ~
153
+ z_value: ~
154
+ turning_moment: ~
155
+ forward_pressure: ~
156
+ -
157
+ - !ruby/object:SkiBinding::Setting
158
+ range: !ruby/range 1..250
159
+ z_value: 2.75
160
+ turning_moment: &turning_moment 23
161
+ forward_pressure: &forward_pressure 87
162
+ - !ruby/object:SkiBinding::Setting
163
+ range: !ruby/range 251..270
164
+ z_value: 2.5
165
+ turning_moment: *turning_moment
166
+ forward_pressure: *forward_pressure
167
+ - !ruby/object:SkiBinding::Setting
168
+ range: !ruby/range 271..290
169
+ z_value: 2.25
170
+ turning_moment: *turning_moment
171
+ forward_pressure: *forward_pressure
172
+ - !ruby/object:SkiBinding::Setting
173
+ range: !ruby/range 291..310
174
+ z_value: 2
175
+ turning_moment: *turning_moment
176
+ forward_pressure: *forward_pressure
177
+ - !ruby/object:SkiBinding::Setting
178
+ range: !ruby/range 311..330
179
+ z_value: 1.75
180
+ turning_moment: *turning_moment
181
+ forward_pressure: *forward_pressure
182
+ - !ruby/object:SkiBinding::Setting
183
+ range: !ruby/range
184
+ begin: 331
185
+ end: .inf
186
+ z_value: 1.75
187
+ turning_moment: *turning_moment
188
+ forward_pressure: *forward_pressure
189
+ -
190
+ - !ruby/object:SkiBinding::Setting
191
+ range: !ruby/range 1..250
192
+ z_value: 3.5
193
+ turning_moment: &turning_moment 27
194
+ forward_pressure: &forward_pressure 102
195
+ - !ruby/object:SkiBinding::Setting
196
+ range: !ruby/range 251..270
197
+ z_value: 3
198
+ turning_moment: *turning_moment
199
+ forward_pressure: *forward_pressure
200
+ - !ruby/object:SkiBinding::Setting
201
+ range: !ruby/range 271..290
202
+ z_value: 2.75
203
+ turning_moment: *turning_moment
204
+ forward_pressure: *forward_pressure
205
+ - !ruby/object:SkiBinding::Setting
206
+ range: !ruby/range 291..310
207
+ z_value: 2.5
208
+ turning_moment: *turning_moment
209
+ forward_pressure: *forward_pressure
210
+ - !ruby/object:SkiBinding::Setting
211
+ range: !ruby/range 311..330
212
+ z_value: 2.25
213
+ turning_moment: *turning_moment
214
+ forward_pressure: *forward_pressure
215
+ - !ruby/object:SkiBinding::Setting
216
+ range: !ruby/range
217
+ begin: 331
218
+ end: .inf
219
+ z_value: 2
220
+ turning_moment: *turning_moment
221
+ forward_pressure: *forward_pressure
222
+ -
223
+ - !ruby/object:SkiBinding::Setting
224
+ range: !ruby/range 1..250
225
+ z_value: 3.5
226
+ turning_moment: &turning_moment 31
227
+ forward_pressure: &forward_pressure 120
228
+ - !ruby/object:SkiBinding::Setting
229
+ range: !ruby/range 251..270
230
+ z_value: 3.5
231
+ turning_moment: *turning_moment
232
+ forward_pressure: *forward_pressure
233
+ - !ruby/object:SkiBinding::Setting
234
+ range: !ruby/range 271..290
235
+ z_value: 3
236
+ turning_moment: *turning_moment
237
+ forward_pressure: *forward_pressure
238
+ - !ruby/object:SkiBinding::Setting
239
+ range: !ruby/range 291..310
240
+ z_value: 3
241
+ turning_moment: *turning_moment
242
+ forward_pressure: *forward_pressure
243
+ - !ruby/object:SkiBinding::Setting
244
+ range: !ruby/range 311..330
245
+ z_value: 2.75
246
+ turning_moment: *turning_moment
247
+ forward_pressure: *forward_pressure
248
+ - !ruby/object:SkiBinding::Setting
249
+ range: !ruby/range
250
+ begin: 331
251
+ end: .inf
252
+ z_value: 2.5
253
+ turning_moment: *turning_moment
254
+ forward_pressure: *forward_pressure
255
+ -
256
+ - !ruby/object:SkiBinding::Setting
257
+ range: !ruby/range 1..250
258
+ z_value: 3.5
259
+ turning_moment: &turning_moment 37
260
+ forward_pressure: &forward_pressure 141
261
+ - !ruby/object:SkiBinding::Setting
262
+ range: !ruby/range 251..270
263
+ z_value: 4.5
264
+ turning_moment: *turning_moment
265
+ forward_pressure: *forward_pressure
266
+ - !ruby/object:SkiBinding::Setting
267
+ range: !ruby/range 271..290
268
+ z_value: 4
269
+ turning_moment: *turning_moment
270
+ forward_pressure: *forward_pressure
271
+ - !ruby/object:SkiBinding::Setting
272
+ range: !ruby/range 291..310
273
+ z_value: 3.5
274
+ turning_moment: *turning_moment
275
+ forward_pressure: *forward_pressure
276
+ - !ruby/object:SkiBinding::Setting
277
+ range: !ruby/range 311..330
278
+ z_value: 3.5
279
+ turning_moment: *turning_moment
280
+ forward_pressure: *forward_pressure
281
+ - !ruby/object:SkiBinding::Setting
282
+ range: !ruby/range
283
+ begin: 331
284
+ end: .inf
285
+ z_value: 3
286
+ turning_moment: *turning_moment
287
+ forward_pressure: *forward_pressure
288
+ -
289
+ - !ruby/object:SkiBinding::Setting
290
+ range: !ruby/range 1..250
291
+ z_value: 3.5
292
+ turning_moment: &turning_moment 43
293
+ forward_pressure: &forward_pressure 165
294
+ - !ruby/object:SkiBinding::Setting
295
+ range: !ruby/range 251..270
296
+ z_value: 5.5
297
+ turning_moment: *turning_moment
298
+ forward_pressure: *forward_pressure
299
+ - !ruby/object:SkiBinding::Setting
300
+ range: !ruby/range 271..290
301
+ z_value: 5
302
+ turning_moment: *turning_moment
303
+ forward_pressure: *forward_pressure
304
+ - !ruby/object:SkiBinding::Setting
305
+ range: !ruby/range 291..310
306
+ z_value: 4.5
307
+ turning_moment: *turning_moment
308
+ forward_pressure: *forward_pressure
309
+ - !ruby/object:SkiBinding::Setting
310
+ range: !ruby/range 311..330
311
+ z_value: 4
312
+ turning_moment: *turning_moment
313
+ forward_pressure: *forward_pressure
314
+ - !ruby/object:SkiBinding::Setting
315
+ range: !ruby/range
316
+ begin: 331
317
+ end: .inf
318
+ z_value: 3.5
319
+ turning_moment: *turning_moment
320
+ forward_pressure: *forward_pressure
321
+ -
322
+ - !ruby/object:SkiBinding::Setting
323
+ range: !ruby/range 1..250
324
+ z_value: 3.5
325
+ turning_moment: &turning_moment 50
326
+ forward_pressure: &forward_pressure 194
327
+ - !ruby/object:SkiBinding::Setting
328
+ range: !ruby/range 251..270
329
+ z_value: 6.5
330
+ turning_moment: *turning_moment
331
+ forward_pressure: *forward_pressure
332
+ - !ruby/object:SkiBinding::Setting
333
+ range: !ruby/range 271..290
334
+ z_value: 6
335
+ turning_moment: *turning_moment
336
+ forward_pressure: *forward_pressure
337
+ - !ruby/object:SkiBinding::Setting
338
+ range: !ruby/range 291..310
339
+ z_value: 5.5
340
+ turning_moment: *turning_moment
341
+ forward_pressure: *forward_pressure
342
+ - !ruby/object:SkiBinding::Setting
343
+ range: !ruby/range 311..330
344
+ z_value: 5
345
+ turning_moment: *turning_moment
346
+ forward_pressure: *forward_pressure
347
+ - !ruby/object:SkiBinding::Setting
348
+ range: !ruby/range
349
+ begin: 331
350
+ end: .inf
351
+ z_value: 4.5
352
+ turning_moment: *turning_moment
353
+ forward_pressure: *forward_pressure
354
+ -
355
+ - !ruby/object:SkiBinding::Setting
356
+ range: !ruby/range 1..250
357
+ z_value: 3.5
358
+ turning_moment: &turning_moment 58
359
+ forward_pressure: &forward_pressure 229
360
+ - !ruby/object:SkiBinding::Setting
361
+ range: !ruby/range 251..270
362
+ z_value: 7.5
363
+ turning_moment: *turning_moment
364
+ forward_pressure: *forward_pressure
365
+ - !ruby/object:SkiBinding::Setting
366
+ range: !ruby/range 271..290
367
+ z_value: 7
368
+ turning_moment: *turning_moment
369
+ forward_pressure: *forward_pressure
370
+ - !ruby/object:SkiBinding::Setting
371
+ range: !ruby/range 291..310
372
+ z_value: 6.5
373
+ turning_moment: *turning_moment
374
+ forward_pressure: *forward_pressure
375
+ - !ruby/object:SkiBinding::Setting
376
+ range: !ruby/range 311..330
377
+ z_value: 6
378
+ turning_moment: *turning_moment
379
+ forward_pressure: *forward_pressure
380
+ - !ruby/object:SkiBinding::Setting
381
+ range: !ruby/range
382
+ begin: 331
383
+ end: .inf
384
+ z_value: 5.5
385
+ turning_moment: *turning_moment
386
+ forward_pressure: *forward_pressure
387
+ -
388
+ - !ruby/object:SkiBinding::Setting
389
+ range: !ruby/range 1..250
390
+ z_value: 3.5
391
+ turning_moment: &turning_moment 67
392
+ forward_pressure: &forward_pressure 271
393
+ - !ruby/object:SkiBinding::Setting
394
+ range: !ruby/range 251..270
395
+ z_value: 7.5
396
+ turning_moment: *turning_moment
397
+ forward_pressure: *forward_pressure
398
+ - !ruby/object:SkiBinding::Setting
399
+ range: !ruby/range 271..290
400
+ z_value: 8.5
401
+ turning_moment: *turning_moment
402
+ forward_pressure: *forward_pressure
403
+ - !ruby/object:SkiBinding::Setting
404
+ range: !ruby/range 291..310
405
+ z_value: 8
406
+ turning_moment: *turning_moment
407
+ forward_pressure: *forward_pressure
408
+ - !ruby/object:SkiBinding::Setting
409
+ range: !ruby/range 311..330
410
+ z_value: 7
411
+ turning_moment: *turning_moment
412
+ forward_pressure: *forward_pressure
413
+ - !ruby/object:SkiBinding::Setting
414
+ range: !ruby/range
415
+ begin: 331
416
+ end: .inf
417
+ z_value: 6.5
418
+ turning_moment: *turning_moment
419
+ forward_pressure: *forward_pressure
420
+ -
421
+ - !ruby/object:SkiBinding::Setting
422
+ range: !ruby/range 1..250
423
+ z_value: 3.5
424
+ turning_moment: &turning_moment 78
425
+ forward_pressure: &forward_pressure 320
426
+ - !ruby/object:SkiBinding::Setting
427
+ range: !ruby/range 251..270
428
+ z_value: 7.5
429
+ turning_moment: *turning_moment
430
+ forward_pressure: *forward_pressure
431
+ - !ruby/object:SkiBinding::Setting
432
+ range: !ruby/range 271..290
433
+ z_value: 10
434
+ turning_moment: *turning_moment
435
+ forward_pressure: *forward_pressure
436
+ - !ruby/object:SkiBinding::Setting
437
+ range: !ruby/range 291..310
438
+ z_value: 9.5
439
+ turning_moment: *turning_moment
440
+ forward_pressure: *forward_pressure
441
+ - !ruby/object:SkiBinding::Setting
442
+ range: !ruby/range 311..330
443
+ z_value: 8.5
444
+ turning_moment: *turning_moment
445
+ forward_pressure: *forward_pressure
446
+ - !ruby/object:SkiBinding::Setting
447
+ range: !ruby/range
448
+ begin: 331
449
+ end: .inf
450
+ z_value: 8
451
+ turning_moment: *turning_moment
452
+ forward_pressure: *forward_pressure
453
+ -
454
+ - !ruby/object:SkiBinding::Setting
455
+ range: !ruby/range 1..250
456
+ z_value: 3.5
457
+ turning_moment: &turning_moment 91
458
+ forward_pressure: &forward_pressure 380
459
+ - !ruby/object:SkiBinding::Setting
460
+ range: !ruby/range 251..270
461
+ z_value: 7.5
462
+ turning_moment: *turning_moment
463
+ forward_pressure: *forward_pressure
464
+ - !ruby/object:SkiBinding::Setting
465
+ range: !ruby/range 271..290
466
+ z_value: 11.5
467
+ turning_moment: *turning_moment
468
+ forward_pressure: *forward_pressure
469
+ - !ruby/object:SkiBinding::Setting
470
+ range: !ruby/range 291..310
471
+ z_value: 11
472
+ turning_moment: *turning_moment
473
+ forward_pressure: *forward_pressure
474
+ - !ruby/object:SkiBinding::Setting
475
+ range: !ruby/range 311..330
476
+ z_value: 10
477
+ turning_moment: *turning_moment
478
+ forward_pressure: *forward_pressure
479
+ - !ruby/object:SkiBinding::Setting
480
+ range: !ruby/range
481
+ begin: 331
482
+ end: .inf
483
+ z_value: 9.5
484
+ turning_moment: *turning_moment
485
+ forward_pressure: *forward_pressure
@@ -0,0 +1,37 @@
1
+ require 'calculator/config_loader'
2
+
3
+ class SkiBinding::Calculator
4
+ extend ConfigLoader
5
+
6
+ def self.setting(person)
7
+ code = self.binding_code(person)
8
+ self.binding_setting(code, person)
9
+ end
10
+
11
+ private
12
+
13
+ def self.binding_code(person)
14
+ code = -1
15
+ self.load_binding_codes.each_with_index do |c,i|
16
+ code = i
17
+ break if c.weight.include?(person.weight) ||
18
+ c.height.include?(person.height)
19
+ end
20
+ unless person.weight < 13
21
+ code += person.type
22
+ if person.age >= 50 || person.age < 10
23
+ code -= 1
24
+ end
25
+ end
26
+ code
27
+ end
28
+
29
+ def self.binding_setting(code, person)
30
+ settings = self.load_binding_settings(code)
31
+ settings.each do |s|
32
+ return {"z_value" => s.z_value,
33
+ "turning_moment" => s.turning_moment,
34
+ "forward_pressure" => s.forward_pressure} if s.range.include?(person.shoe_size)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ class SkiBinding::Code
2
+ attr_reader :weight, :height
3
+ end
@@ -3,43 +3,21 @@ require 'yaml'
3
3
  module ConfigLoader
4
4
  extend self
5
5
 
6
- def criterias
7
- criterias = []
8
- load_criterias.each do |c|
9
- criterias << Criteria.new(c)
10
- end
11
- criterias
6
+ def load_binding_codes
7
+ binding_codes ||= parse_yml("binding_codes.yml")
12
8
  end
13
-
14
- def indices
15
- indices = []
16
- load_indices.each do |code|
17
- code[1].each do |v|
18
- indices << Index.new(code[0], v)
19
- end
20
- end
21
- indices
22
- end
23
-
24
- def load_indices
25
- indices ||= parse_yml("indices.yml")
26
- end
27
-
28
-
29
- def load_criterias
30
- criterias ||= parse_yml("criterias.yml")
9
+
10
+ def load_binding_settings(code)
11
+ binding_settings ||= parse_yml("binding_settings.yml")
12
+ binding_settings[code]
31
13
  end
32
14
 
33
15
  private
34
-
35
- def file_path
36
- path ||= File.expand_path("../../../config", __FILE__)
37
- end
38
-
39
- def parse_yml(filename)
40
-
41
-
42
- YAML::load(File.open("#{file_path}/#{filename}"))
43
- end
44
-
16
+ def file_path
17
+ path ||= File.expand_path("../../../config", __FILE__)
18
+ end
19
+
20
+ def parse_yml(filename)
21
+ YAML::load(File.open("#{file_path}/#{filename}"))
22
+ end
45
23
  end
@@ -0,0 +1,3 @@
1
+ class SkiBinding::Setting
2
+ attr_reader :range , :z_value, :turning_moment, :forward_pressure
3
+ end
data/lib/person.rb ADDED
@@ -0,0 +1,22 @@
1
+ class SkiBinding::Person
2
+ include ConfigLoader
3
+
4
+ attr_reader :type, :weight, :height, :shoe_size, :age
5
+
6
+ def initialize(values_hash)
7
+ @type = validate_type(values_hash["type"] || values_hash[:type])
8
+ @weight = values_hash["weight"] || values_hash[:weight]
9
+ @height = values_hash["height"] || values_hash[:height]
10
+ @shoe_size = values_hash["shoe_size"] || values_hash[:shoe_size]
11
+ @age = values_hash["age"] || values_hash[:age]
12
+ end
13
+
14
+ private
15
+
16
+ def validate_type(type)
17
+ types = {"Type1-" => -1, "Type1" => 0, "Type2" => 1,
18
+ "Type3" => 2, "Type3+" => 3}
19
+ keys = types.keys
20
+ types[type] if keys.include?(type)
21
+ end
22
+ end
@@ -0,0 +1,2 @@
1
+ module SkiBinding
2
+ end
@@ -1,5 +1,6 @@
1
- require 'calculator/binding_calculator'
2
- require 'calculator/driver_type'
1
+ require 'ski_binding'
2
+ require 'calculator/calculator'
3
3
  require 'calculator/config_loader'
4
- require 'calculator/criteria'
5
- require 'calculator/index'
4
+ require 'calculator/code'
5
+ require 'calculator/setting'
6
+ require 'person'
@@ -1,16 +1,18 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'ski_binding_calculator'
4
- s.version = '0.0.2'
5
- s.date = '2013-07-28'
4
+ s.version = '0.5.0'
5
+ s.date = '2013-08-04'
6
6
  s.summary = "Ski Binding Calculator"
7
7
  s.description = "A little gem to calculate the z-value accord to the iso 11088 norm."
8
8
  s.authors = ["Jonas Ruef, Felix Langenegger"]
9
9
  s.email = 'support@fadendaten.ch'
10
10
  s.homepage = 'http://fadendaten.ch'
11
+ s.license = 'MIT'
11
12
 
12
13
  s.add_development_dependency "rspec", "~> 2.14.1"
13
14
  s.add_development_dependency "spork", "~> 0.9.2"
15
+ s.add_development_dependency "simplecov", "~> 0.7.1"
14
16
 
15
17
  s.files = Dir.glob("{config,lib,spec}/**/*")
16
18
  s.files += %w(Rakefile ski_binding_calculator.gemspec)
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe SkiBinding::Calculator do
4
+ before(:all) do
5
+ @calculator = SkiBinding::Calculator.new
6
+ hash = {:type => "Type2", :weight => 70,
7
+ :height => 170, :shoe_size => 315, :age => 30}
8
+ @person = SkiBinding::Person.new(hash)
9
+ end
10
+
11
+ describe "new" do
12
+ it "returns a BindingCalculator class" do
13
+ SkiBinding::Calculator.new.class.should == SkiBinding::Calculator
14
+ end
15
+ end
16
+
17
+ describe "config loader" do
18
+ it "responds to binding_settings" do
19
+ SkiBinding::Calculator.should respond_to :setting
20
+ end
21
+
22
+ it "responds to binding_codes" do
23
+ SkiBinding::Calculator.should respond_to :binding_code
24
+ end
25
+
26
+ it "responds to binding_settings" do
27
+ SkiBinding::Calculator.should respond_to :binding_setting
28
+ end
29
+ end
30
+
31
+ describe "#setting" do
32
+ it "returns a valid setting" do
33
+ SkiBinding::Calculator.setting(@person).should ==
34
+ {"z_value"=>6, "turning_moment"=>58, "forward_pressure"=>229}
35
+ end
36
+ end
37
+
38
+ describe "#binding_code" do
39
+ it "returns a valid code" do
40
+ SkiBinding::Calculator.binding_code(@person).should == 11
41
+ end
42
+
43
+ it "returns code one less than before if age >= 50" do
44
+ hash = {:type => "Type2", :weight => 70,
45
+ :height => 170, :shoe_size => 315, :age => 50}
46
+ @person = SkiBinding::Person.new(hash)
47
+ SkiBinding::Calculator.binding_code(@person).should == 10
48
+ hash[:age] = 51
49
+ @person = SkiBinding::Person.new(hash)
50
+ SkiBinding::Calculator.binding_code(@person).should == 10
51
+ end
52
+
53
+ it "returns code unchanged if weight less than 13kg" do
54
+ hash = {:type => "Type2", :weight => 12,
55
+ :height => 147, :shoe_size => 249, :age => 30}
56
+ @person = SkiBinding::Person.new(hash)
57
+ SkiBinding::Calculator.binding_code(@person).should == 0
58
+ end
59
+ end
60
+
61
+ describe "#binding_setting" do
62
+ it "returns a valid setting" do
63
+ SkiBinding::Calculator.binding_setting(11, @person).should ==
64
+ {"z_value"=>6, "turning_moment"=>58, "forward_pressure"=>229}
65
+ end
66
+ end
67
+ end
data/spec/code_spec.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe SkiBinding::Code do
4
+ describe "new" do
5
+ it "should return a Code class" do
6
+ SkiBinding::Code.new.class.should == SkiBinding::Code
7
+ end
8
+ end
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
22
+ end
23
+ end
24
+
@@ -2,37 +2,71 @@ require 'spec_helper'
2
2
 
3
3
  describe "ConfigLoader" do
4
4
 
5
- before(:each) do
5
+ before(:all) do
6
+ @range = 0..14 #cause 14 codes
6
7
  @dummy_class = DummyClass.new
7
8
  @dummy_class.extend(ConfigLoader)
8
9
  end
9
10
 
10
- describe "loading config" do
11
- it "should load a config file" do
12
- @dummy_class.load_criterias.class.should == Array
11
+ describe "loading binding codes:" do
12
+ it "something gets loaded" do
13
+ @dummy_class.load_binding_codes.class.should_not == nil
13
14
  end
14
- end
15
-
16
- describe "first element of the array" do
17
- it "should be a hash" do
18
- @dummy_class.load_criterias[0].class.should == Hash
19
- end
20
-
21
- it "should not be a string" do
22
- @dummy_class.load_criterias[0].class.should_not == String
15
+
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
24
+
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
23
32
  end
24
33
  end
25
-
26
- describe "criterias" do
27
- it "should load all criterias" do
28
- @dummy_class.criterias.class.should == Array
34
+
35
+ 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
29
40
  end
30
-
31
- it "should load the an array of Criterias" do
32
- @dummy_class.criterias[0].class.should == Criteria
41
+
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 == 6
65
+ end
66
+ end
33
67
  end
34
68
  end
35
69
  end
36
70
 
37
71
  class DummyClass
38
- end
72
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe SkiBinding::Person do
4
+ before :all do
5
+ @hash = {:type => "Type2", :weight => 70, :height => 170, :shoe_size => 315, :age => 30}
6
+ end
7
+
8
+ describe "new" do
9
+ it "should return a Person class" do
10
+ SkiBinding::Person.new(@hash).class.should == SkiBinding::Person
11
+ end
12
+ end
13
+
14
+ context "instantiated Person class" do
15
+ before :all do
16
+ @person = SkiBinding::Person.new(@hash)
17
+ end
18
+
19
+ it "has attribute type" do
20
+ @person.should respond_to :type
21
+ end
22
+
23
+ it "has attribute weight" do
24
+ @person.should respond_to :weight
25
+ end
26
+
27
+ it "has attribute heigth" do
28
+ @person.should respond_to :height
29
+ end
30
+
31
+ it "has attribute shoe_size" do
32
+ @person.should respond_to :shoe_size
33
+ end
34
+
35
+ it "has attribute age" do
36
+ @person.should respond_to :age
37
+ end
38
+
39
+ describe "validates type" do
40
+ it "sets \"Type2\" to 1" do
41
+ @person.type.should == 1
42
+ end
43
+
44
+ it "sets type \"unknown\" to nil"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe SkiBinding::Setting do
4
+ describe "new" do
5
+ it "should return a Setting class" do
6
+ SkiBinding::Setting.new.class.should == SkiBinding::Setting
7
+ end
8
+ end
9
+
10
+ context "instantiated Setting class" do
11
+ before :all do
12
+ @setting = SkiBinding::Setting.new
13
+ end
14
+
15
+ it "has attribute range" do
16
+ @setting.should respond_to :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 turning_moment" do
24
+ @setting.should respond_to :turning_moment
25
+ end
26
+
27
+ it "has attribute forward_pressure" do
28
+ @setting.should respond_to :forward_pressure
29
+ end
30
+ end
31
+ end
data/spec/spec_helper.rb CHANGED
@@ -3,16 +3,16 @@ require 'spork'
3
3
 
4
4
  Spork.prefork do
5
5
  require 'rspec'
6
+ require 'simplecov'
7
+ SimpleCov.start
6
8
 
7
9
  unless defined?(SPEC_ROOT)
8
10
  SPEC_ROOT = File.expand_path("../", __FILE__)
9
11
  end
10
12
 
11
-
12
13
  RSpec.configure do |config|
13
14
  end
14
15
 
15
-
16
16
  Spork.each_run do
17
17
  require 'ski_binding_calculator'
18
18
  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.0.2
4
+ version: 0.5.0
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-07-28 00:00:00.000000000 Z
12
+ date: 2013-08-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -43,30 +43,48 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.9.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: simplecov
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.7.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.1
46
62
  description: A little gem to calculate the z-value accord to the iso 11088 norm.
47
63
  email: support@fadendaten.ch
48
64
  executables: []
49
65
  extensions: []
50
66
  extra_rdoc_files: []
51
67
  files:
52
- - config/criterias.yml
53
- - config/indices.yml
54
- - lib/calculator/binding_calculator.rb
68
+ - config/binding_codes.yml
69
+ - config/binding_settings.yml
70
+ - lib/calculator/calculator.rb
71
+ - lib/calculator/code.rb
55
72
  - lib/calculator/config_loader.rb
56
- - lib/calculator/criteria.rb
57
- - lib/calculator/driver_type.rb
58
- - lib/calculator/index.rb
73
+ - lib/calculator/setting.rb
74
+ - lib/person.rb
75
+ - lib/ski_binding.rb
59
76
  - lib/ski_binding_calculator.rb
60
- - spec/binding_calculator_spec.rb
77
+ - spec/calculator_spec.rb
78
+ - spec/code_spec.rb
61
79
  - spec/config_loader_spec.rb
62
- - spec/criteria_spec.rb
63
- - spec/driver_type_spec.rb
64
- - spec/index_spec.rb
80
+ - spec/person_spec.rb
81
+ - spec/setting_spec.rb
65
82
  - spec/spec_helper.rb
66
83
  - Rakefile
67
84
  - ski_binding_calculator.gemspec
68
85
  homepage: http://fadendaten.ch
69
- licenses: []
86
+ licenses:
87
+ - MIT
70
88
  post_install_message:
71
89
  rdoc_options: []
72
90
  require_paths:
data/config/criterias.yml DELETED
@@ -1,6 +0,0 @@
1
- -
2
- weight: !ruby/range 10..13
3
- height: !ruby/range 1..148
4
- -
5
- weight: !ruby/range 14..17
6
- height: !ruby/range 1..148
data/config/indices.yml DELETED
@@ -1,51 +0,0 @@
1
- 0:
2
- - !ruby/range 1..250:
3
- z_value: 0.75
4
- mz: &MZ 8
5
- my: &MY 29
6
- - !ruby/range 251..270:
7
- z_value: 0.75
8
- mz: *MZ
9
- my: *MY
10
-
11
- 1:
12
- - !ruby/range 1..250:
13
- z_value: 1
14
- mz: &mz 11
15
- my: &my 40
16
- - !ruby/range 251..270:
17
- z_value: 1
18
- mz: *mz
19
- my: *my
20
- - !ruby/range 271..290:
21
- z_value: 0.75
22
- mz: *mz
23
- my: *my
24
-
25
- 2:
26
- - !ruby/range 1..250:
27
- z_value: 1
28
- mz: &mz 11
29
- my: &my 40
30
- - !ruby/range 251..270:
31
- z_value: 1
32
- mz: *mz
33
- my: *my
34
- - !ruby/range 271..290:
35
- z_value: 0.75
36
- mz: *mz
37
- my: *my
38
-
39
- 3:
40
- - !ruby/range 1..250:
41
- z_value: 1
42
- mz: &mz 11
43
- my: &my 40
44
- - !ruby/range 251..270:
45
- z_value: 1
46
- mz: *mz
47
- my: *my
48
- - !ruby/range 271..290:
49
- z_value: 0.75
50
- mz: *mz
51
- my: *my
@@ -1,31 +0,0 @@
1
- require 'calculator/config_loader'
2
-
3
- class BindingCalculator
4
- include ConfigLoader
5
-
6
- attr_reader :z_value, :rotation, :pressure
7
-
8
- def initialize(type, weight, height, size)
9
- @type = type
10
- @weight = weight
11
- @height = height
12
- @size = size
13
- end
14
-
15
- def code
16
- code = 0
17
- self.criterias.each_with_index do |c,i|
18
- code = i
19
- break if c.weight.include?(@weight) || c.height.include?(@height)
20
- end
21
- code + @type.moving_value
22
- end
23
-
24
- def z_value
25
- self.indices.each do |i|
26
- return i.z_value if i.size.include?(@size)
27
- end
28
- end
29
-
30
-
31
- end
@@ -1,10 +0,0 @@
1
- class Criteria
2
-
3
- attr_reader :weight, :height
4
-
5
- def initialize(hash)
6
- @weight = hash["weight"] || hash[:weight]
7
- @height= hash["height"] || hash[:height]
8
- end
9
-
10
- end
@@ -1,9 +0,0 @@
1
- class DriverType
2
- attr_reader :name, :moving_value
3
-
4
- def initialize(name, moving_value)
5
- @name = name
6
- @moving_value = moving_value
7
- end
8
-
9
- end
@@ -1,13 +0,0 @@
1
- class Index
2
- attr_reader :index, :size, :z_value, :mz, :my
3
-
4
- def initialize(index, hash)
5
- @index = index
6
- @size = hash.keys.first
7
- hash = hash[@size]
8
- @z_value = hash["z_value"] || hash[:z_value]
9
- @mz = hash["mz"] || hash[:mz]
10
- @my = hash["my"] || hash[:my]
11
- end
12
-
13
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe BindingCalculator do
4
- before(:each) do
5
- @type = DriverType.new("2",2)
6
- @weight = 16
7
- @height = 308
8
- @size = 192
9
- @calculator = BindingCalculator.new(@type, @weight, @height, @size)
10
- end
11
-
12
- describe "new" do
13
- it "should return a BindingCalculator class" do
14
- BindingCalculator.new(@type, @weight, @height, @size).class.should == BindingCalculator
15
- end
16
- end
17
-
18
- describe "config laoder" do
19
- it "should responds to criterias" do
20
- @calculator.should respond_to :criterias
21
- end
22
- it "should responds to load_criterias" do
23
- @calculator.should respond_to :load_criterias
24
- end
25
- end
26
-
27
- describe "code" do
28
- it "should return a valid code" do
29
- @calculator.code.should == 3
30
- end
31
- it "should not be 4" do
32
- @calculator.code.should_not == 4
33
- end
34
- end
35
-
36
- describe "z_value" do
37
- it "should return a Float" do
38
- @calculator.z_value.class.should == Float
39
- end
40
-
41
- it "should return a valid value" do
42
- @calculator.z_value.should == 0.75
43
- end
44
- end
45
-
46
-
47
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- describe Criteria do
5
-
6
- before(:each) do
7
- @hash = {:weight => 10..13, :height => 10..148}
8
- @criteria = Criteria.new(@hash)
9
- end
10
-
11
- describe ".new" do
12
- it "should return a Criteria class" do
13
- Criteria.new(@hash).class.should == Criteria
14
- end
15
- end
16
-
17
- describe "weight" do
18
- it "shoud return the weight rang" do
19
- @criteria.weight.should == (10..13)
20
- end
21
-
22
- it "should be a range" do
23
- @criteria.weight.class.should == Range
24
- end
25
- end
26
-
27
- describe "height" do
28
- it "shoud return the height rang" do
29
- @criteria.height.should == (10..148)
30
- end
31
-
32
- it "should be a range" do
33
- @criteria.height.class.should == Range
34
- end
35
- end
36
-
37
- end
@@ -1,36 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DriverType do
4
-
5
- describe ".new" do
6
- it "should create a new DriverType" do
7
- DriverType.new("1", -1).class.should == DriverType
8
- end
9
- end
10
-
11
- describe "methods" do
12
- before(:each) do
13
- @driver = DriverType.new("1", -1)
14
- end
15
-
16
- describe "name" do
17
- it "should have a driver type name" do
18
- @driver.name.should == "1"
19
- end
20
-
21
- it "should be a string" do
22
- @driver.name.class.should == String
23
- end
24
- end
25
-
26
- describe "moving_value" do
27
- it "should have a moving value" do
28
- @driver.moving_value.should == -1
29
- end
30
-
31
- it "should be a fixnum" do
32
- @driver.moving_value.class.should == Fixnum
33
- end
34
- end
35
- end
36
- end
data/spec/index_spec.rb DELETED
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Index do
4
-
5
- before(:each) do
6
- @hash = {(1..250) => {:z_value => 1.5, :my => 52, :mz => 14}}
7
- @index = Index.new(1, @hash)
8
- end
9
-
10
- describe "new" do
11
- it "should return a Index class" do
12
- Index.new(0, @hash).class.should == Index
13
- end
14
- end
15
-
16
- describe "size" do
17
- it "should return the size range" do
18
- @index.size.should == (1..250)
19
- end
20
-
21
- it "should be a range" do
22
- @index.size.class.should == Range
23
- end
24
- end
25
-
26
- describe "z_value" do
27
- it "should respond to z_value" do
28
- @index.should respond_to :z_value
29
- end
30
-
31
- it "should return the z_value" do
32
- @index.z_value.should == 1.5
33
- end
34
- end
35
-
36
- end