ski_binding_calculator 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -20,18 +20,22 @@ class SkiBinding::Calculator
|
|
20
20
|
end
|
21
21
|
hashy[:height] = attrs[:height].to_f || attrs["height"].to_f
|
22
22
|
hashy[:sole_length] = attrs[:sole_length].to_f || attrs["sole_length"].to_f
|
23
|
-
hashy[:
|
23
|
+
hashy[:birthday_year] = attrs[:birthday_year].to_i || attrs["birthday_year"].to_i
|
24
|
+
hashy[:birthday_month] = attrs[:birthday_month].to_i || attrs["birthday_month"].to_i
|
25
|
+
hashy[:birthday_day] = attrs[:birthday_day].to_i || attrs["birthday_day"].to_i
|
24
26
|
hashy[:type] = attrs[:type] || attrs["type"]
|
25
27
|
hashy
|
26
28
|
end
|
27
29
|
|
28
30
|
def self.age(attrs)
|
29
|
-
birthday = Date.
|
31
|
+
birthday = Date.new(attrs[:birthday_year], attrs[:birthday_month], attrs[:birthday_day])
|
30
32
|
now = Date.today
|
31
33
|
age = now.year - birthday.year
|
32
34
|
age -= ((now.month > birthday.month ||
|
33
35
|
(now.month == birthday.month && now.day >= birthday.day)) ? 0 : 1)
|
34
|
-
attrs.delete(:
|
36
|
+
attrs.delete(:birthday_year)
|
37
|
+
attrs.delete(:birthday_month)
|
38
|
+
attrs.delete(:birthday_day)
|
35
39
|
attrs[:age] = age
|
36
40
|
attrs
|
37
41
|
end
|
data/spec/lib/calculator_spec.rb
CHANGED
@@ -11,14 +11,18 @@ describe SkiBinding::Calculator do
|
|
11
11
|
:weight => "70",
|
12
12
|
:height => "170",
|
13
13
|
:sole_length => "315",
|
14
|
-
:
|
14
|
+
:birthday_year => "1983",
|
15
|
+
:birthday_month => "01",
|
16
|
+
:birthday_day => "01" }
|
15
17
|
end
|
16
18
|
subject(:expected_preped) do
|
17
19
|
{ :type => "Type2",
|
18
20
|
:weight => 70.0,
|
19
21
|
:height => 170.0,
|
20
22
|
:sole_length => 315.0,
|
21
|
-
:
|
23
|
+
:birthday_year => 1983,
|
24
|
+
:birthday_month => 1,
|
25
|
+
:birthday_day => 1 }
|
22
26
|
end
|
23
27
|
subject(:expected_aged) do
|
24
28
|
{ :type => "Type2",
|