Class: Corraios::Containers::Package
- Inherits:
-
Base
- Object
- Base
- Corraios::Containers::Package
show all
- Defined in:
- lib/corraios/containers/package.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
add_attribute, #assert_minimum_measures!, #attributes_names, attributes_restrictions, floor_for, #format, #initialize, #is_a?, minimum_value_for, query_attribute_name, query_attribute_names, set_format, #to_query_params, #valid?, valid_field?
Class Method Details
.valid_fields?(attributes) ⇒ Boolean
40
41
42
43
|
# File 'lib/corraios/containers/package.rb', line 40
def valid_fields?(attributes)
super(attributes) &&
(attributes[:width] + attributes[:height] + attributes[:length]) <= 200.0
end
|
Instance Method Details
#can_merge?(other) ⇒ Boolean
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/corraios/containers/package.rb', line 12
def can_merge?(other)
new_volume = self.volume + other.volume
new_sides_size = (new_volume ** (1.0/3))
attributes = { weight: self.weight + other.weight }
[:width, :length, :height].each do |attr|
attributes[attr] = self.class.floor_for attr, new_sides_size
end
self.class.valid_fields? attributes
end
|
#merge!(other) ⇒ Object
24
25
26
27
28
|
# File 'lib/corraios/containers/package.rb', line 24
def merge!(other)
self.weight += other.weight
self.width = self.length = self.height = ((self.volume + other.volume) ** (1.0/3))
assert_minimum_measures!
end
|
#to_package ⇒ Object
34
35
36
|
# File 'lib/corraios/containers/package.rb', line 34
def to_package
self
end
|
#volume ⇒ Object
30
31
32
|
# File 'lib/corraios/containers/package.rb', line 30
def volume
width * length * height
end
|