ski_binding_calculator 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'rake/clean'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new
@@ -0,0 +1,6 @@
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
@@ -0,0 +1,51 @@
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
@@ -0,0 +1,31 @@
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
@@ -0,0 +1,45 @@
1
+ require 'yaml'
2
+
3
+ module ConfigLoader
4
+ extend self
5
+
6
+ def criterias
7
+ criterias = []
8
+ load_criterias.each do |c|
9
+ criterias << Criteria.new(c)
10
+ end
11
+ criterias
12
+ 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")
31
+ end
32
+
33
+ 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
+
45
+ end
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,13 @@
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
@@ -0,0 +1,5 @@
1
+ require 'calculator/binding_calculator'
2
+ require 'calculator/driver_type'
3
+ require 'calculator/config_loader'
4
+ require 'calculator/criteria'
5
+ require 'calculator/index'
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'ski_binding_calculator'
4
+ s.version = '0.0.2'
5
+ s.date = '2013-07-28'
6
+ s.summary = "Ski Binding Calculator"
7
+ s.description = "A little gem to calculate the z-value accord to the iso 11088 norm."
8
+ s.authors = ["Jonas Ruef, Felix Langenegger"]
9
+ s.email = 'support@fadendaten.ch'
10
+ s.homepage = 'http://fadendaten.ch'
11
+
12
+ s.add_development_dependency "rspec", "~> 2.14.1"
13
+ s.add_development_dependency "spork", "~> 0.9.2"
14
+
15
+ s.files = Dir.glob("{config,lib,spec}/**/*")
16
+ s.files += %w(Rakefile ski_binding_calculator.gemspec)
17
+ end
@@ -0,0 +1,47 @@
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
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe "ConfigLoader" do
4
+
5
+ before(:each) do
6
+ @dummy_class = DummyClass.new
7
+ @dummy_class.extend(ConfigLoader)
8
+ end
9
+
10
+ describe "loading config" do
11
+ it "should load a config file" do
12
+ @dummy_class.load_criterias.class.should == Array
13
+ 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
23
+ end
24
+ end
25
+
26
+ describe "criterias" do
27
+ it "should load all criterias" do
28
+ @dummy_class.criterias.class.should == Array
29
+ end
30
+
31
+ it "should load the an array of Criterias" do
32
+ @dummy_class.criterias[0].class.should == Criteria
33
+ end
34
+ end
35
+ end
36
+
37
+ class DummyClass
38
+ end
@@ -0,0 +1,37 @@
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
@@ -0,0 +1,36 @@
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
@@ -0,0 +1,36 @@
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
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'spork'
3
+
4
+ Spork.prefork do
5
+ require 'rspec'
6
+
7
+ unless defined?(SPEC_ROOT)
8
+ SPEC_ROOT = File.expand_path("../", __FILE__)
9
+ end
10
+
11
+
12
+ RSpec.configure do |config|
13
+ end
14
+
15
+
16
+ Spork.each_run do
17
+ require 'ski_binding_calculator'
18
+ end
19
+ end
20
+
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ski_binding_calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jonas Ruef, Felix Langenegger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.14.1
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.14.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: spork
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.9.2
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.2
46
+ description: A little gem to calculate the z-value accord to the iso 11088 norm.
47
+ email: support@fadendaten.ch
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - config/criterias.yml
53
+ - config/indices.yml
54
+ - lib/calculator/binding_calculator.rb
55
+ - lib/calculator/config_loader.rb
56
+ - lib/calculator/criteria.rb
57
+ - lib/calculator/driver_type.rb
58
+ - lib/calculator/index.rb
59
+ - lib/ski_binding_calculator.rb
60
+ - spec/binding_calculator_spec.rb
61
+ - spec/config_loader_spec.rb
62
+ - spec/criteria_spec.rb
63
+ - spec/driver_type_spec.rb
64
+ - spec/index_spec.rb
65
+ - spec/spec_helper.rb
66
+ - Rakefile
67
+ - ski_binding_calculator.gemspec
68
+ homepage: http://fadendaten.ch
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 1.8.25
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Ski Binding Calculator
92
+ test_files: []