general_units 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/general_units/derivatives/box.rb +25 -15
- data/lib/general_units/units/length.rb +1 -1
- data/lib/general_units/units/weight.rb +1 -1
- data/lib/general_units/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b587736e5f764d47a5633f38ae9e871078a9d2d
|
4
|
+
data.tar.gz: 91594f7393deb805d8a15ffbdeddaeaded832e18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ec7e49bc0fb3bf97304216b650fbb1f23db262ca31475db84be92448b116e2d9e033be3a3002e3ab176dc9d715d5cdf30a79cb112614c321bad755de23eb98c
|
7
|
+
data.tar.gz: f75851118b3fcbbeda331e3999d2a6d205984ffd6fac174ea65512f4ce84eb552078055c9f729323c7399e6213ca6f0b9bf060085437096a2537417f98e708dc
|
@@ -8,7 +8,7 @@ module GeneralUnits
|
|
8
8
|
|
9
9
|
attr_reader *VALUES, :unit
|
10
10
|
|
11
|
-
delegate :to_f, :to => :
|
11
|
+
delegate :to_f, :to => :volume
|
12
12
|
delegate :hash, :to => :attributes
|
13
13
|
|
14
14
|
def initialize(length = 0, width = 0, height = 0, unit)
|
@@ -23,10 +23,18 @@ module GeneralUnits
|
|
23
23
|
def values
|
24
24
|
VALUES.map {|v| self.send(v)}
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def amount
|
28
|
+
values.sum
|
29
|
+
end
|
30
|
+
|
31
|
+
def volume
|
28
32
|
length * width * height
|
29
33
|
end
|
34
|
+
|
35
|
+
def has_space?
|
36
|
+
length > 0 && width > 0 && height > 0
|
37
|
+
end
|
30
38
|
|
31
39
|
def convert_to(unit)
|
32
40
|
Box.new(*values.map {|v| v.convert_to(unit).amount}, unit)
|
@@ -42,7 +50,7 @@ module GeneralUnits
|
|
42
50
|
|
43
51
|
def accommodates?(*boxes)
|
44
52
|
boxes.map! {|box| validate_capacity(box)}
|
45
|
-
boxes.sum(&:
|
53
|
+
boxes.sum(&:volume) < volume && includes?(Box.new(boxes.map(&:length).max, boxes.map(&:width).max, boxes.map(&:height).max, unit))
|
46
54
|
end
|
47
55
|
|
48
56
|
def same_size?(other_object)
|
@@ -64,6 +72,8 @@ module GeneralUnits
|
|
64
72
|
def ==(other_object)
|
65
73
|
other_object = validate_capacity(other_object)
|
66
74
|
length == other_object.length && width == other_object.width && height == other_object.height
|
75
|
+
rescue
|
76
|
+
false
|
67
77
|
end
|
68
78
|
|
69
79
|
def eql?(other_object)
|
@@ -72,45 +82,45 @@ module GeneralUnits
|
|
72
82
|
|
73
83
|
def <=>(other_object)
|
74
84
|
other_object = validate_capacity_or_length(other_object)
|
75
|
-
|
85
|
+
volume <=> case other_object
|
76
86
|
when Length then other_object
|
77
|
-
when Box then other_object.
|
87
|
+
when Box then other_object.volume
|
78
88
|
end
|
79
89
|
end
|
80
90
|
|
81
91
|
def >(other_object)
|
82
92
|
other_object = validate_capacity_or_length(other_object)
|
83
|
-
|
93
|
+
volume > case other_object
|
84
94
|
when Length then other_object
|
85
|
-
when Box then other_object.
|
95
|
+
when Box then other_object.volume
|
86
96
|
end
|
87
97
|
end
|
88
98
|
|
89
99
|
def <(other_object)
|
90
100
|
other_object = validate_capacity_or_length(other_object)
|
91
|
-
|
101
|
+
volume < case other_object
|
92
102
|
when Length then other_object
|
93
|
-
when Box then other_object.
|
103
|
+
when Box then other_object.volume
|
94
104
|
end
|
95
105
|
end
|
96
106
|
|
97
107
|
def >=(other_object)
|
98
108
|
other_object = validate_capacity_or_length(other_object)
|
99
|
-
|
109
|
+
volume >= case other_object
|
100
110
|
when Length then other_object
|
101
|
-
when Box then other_object.
|
111
|
+
when Box then other_object.volume
|
102
112
|
end
|
103
113
|
end
|
104
114
|
|
105
115
|
def <=(other_object)
|
106
116
|
other_object = validate_capacity_or_length(other_object)
|
107
|
-
|
117
|
+
volume <= case other_object
|
108
118
|
when Length then other_object
|
109
|
-
when Box then other_object.
|
119
|
+
when Box then other_object.volume
|
110
120
|
end
|
111
121
|
end
|
112
122
|
|
113
|
-
delegate :positive?, :negative?, :to => :
|
123
|
+
delegate :positive?, :negative?, :to => :volume
|
114
124
|
|
115
125
|
def +(other_object)
|
116
126
|
other_object = validate_capacity_or_length(other_object)
|
@@ -144,7 +154,7 @@ module GeneralUnits
|
|
144
154
|
end
|
145
155
|
end
|
146
156
|
|
147
|
-
delegate :div, :divmod, :modulo, :%, :remainder, :abs, :zero?, :nonzero?, :coerce, :to => :
|
157
|
+
delegate :div, :divmod, :modulo, :%, :remainder, :abs, :zero?, :nonzero?, :coerce, :to => :volume
|
148
158
|
|
149
159
|
### ARITHMETICS END ###
|
150
160
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: general_units
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valery Kvon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|