Class: OfficeClerk::Post
- Inherits:
-
ShippingMethod
- Object
- ShippingMethod
- OfficeClerk::Post
- Defined in:
- lib/office_clerk/post.rb
Constant Summary collapse
- DEFAULTS =
{ :weight_table => '1 2 5 10 20' , :price_table => '2 5 10 15 18' , :max_item_weight => "20" , :max_price => "100" , :handling_max => "20" , :handling_fee => "0" , :default_weight => "1" }
Instance Attribute Summary collapse
-
#default_weight ⇒ Object
readonly
Returns the value of attribute default_weight.
-
#handling_fee ⇒ Object
readonly
Returns the value of attribute handling_fee.
-
#handling_max ⇒ Object
readonly
Returns the value of attribute handling_max.
-
#max_item_weight ⇒ Object
readonly
Returns the value of attribute max_item_weight.
-
#max_price ⇒ Object
readonly
Returns the value of attribute max_price.
-
#prices ⇒ Object
readonly
Returns the value of attribute prices.
-
#weights ⇒ Object
readonly
Returns the value of attribute weights.
Instance Method Summary collapse
-
#available?(basket) ⇒ Boolean
Determine if weight or size goes over bounds.
-
#initialize(data) ⇒ Post
constructor
A new instance of Post.
- #price_for(basket) ⇒ Object
Constructor Details
Instance Attribute Details
#default_weight ⇒ Object (readonly)
Returns the value of attribute default_weight.
17 18 19 |
# File 'lib/office_clerk/post.rb', line 17 def default_weight @default_weight end |
#handling_fee ⇒ Object (readonly)
Returns the value of attribute handling_fee.
17 18 19 |
# File 'lib/office_clerk/post.rb', line 17 def handling_fee @handling_fee end |
#handling_max ⇒ Object (readonly)
Returns the value of attribute handling_max.
17 18 19 |
# File 'lib/office_clerk/post.rb', line 17 def handling_max @handling_max end |
#max_item_weight ⇒ Object (readonly)
Returns the value of attribute max_item_weight.
17 18 19 |
# File 'lib/office_clerk/post.rb', line 17 def max_item_weight @max_item_weight end |
#max_price ⇒ Object (readonly)
Returns the value of attribute max_price.
17 18 19 |
# File 'lib/office_clerk/post.rb', line 17 def max_price @max_price end |
#prices ⇒ Object (readonly)
Returns the value of attribute prices.
17 18 19 |
# File 'lib/office_clerk/post.rb', line 17 def prices @prices end |
#weights ⇒ Object (readonly)
Returns the value of attribute weights.
17 18 19 |
# File 'lib/office_clerk/post.rb', line 17 def weights @weights end |
Instance Method Details
#available?(basket) ⇒ Boolean
Determine if weight or size goes over bounds.
20 21 22 23 24 25 26 27 |
# File 'lib/office_clerk/post.rb', line 20 def available?(basket) basket.items.each do |item| if( weight = item.product.weight) return false if weight > max_item_weight end end true end |
#price_for(basket) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/office_clerk/post.rb', line 29 def price_for(basket) total_price = basket.total_price return 0.0 if total_price > self.max_price total_weight = basket.items.map {|item| item.quantity * (item.product.weight || default_weight) }.reduce(:+) || 0.0 shipping = 0 while total_weight > weights.last # In several packets if need be. total_weight -= weights.last shipping += prices.last end [shipping, prices[compute_index(total_weight)], calc_handling_fee(total_price)].compact.sum end |