Class: FreightKit::Tariff::OverlengthRule
- Inherits:
-
Object
- Object
- FreightKit::Tariff::OverlengthRule
- Defined in:
- lib/freight_kit/tariff/overlength_rule.rb
Instance Attribute Summary collapse
-
#fee_cents ⇒ Object
readonly
Returns the value of attribute fee_cents.
-
#max_length ⇒ Object
readonly
Returns the value of attribute max_length.
-
#min_length ⇒ Object
readonly
Returns the value of attribute min_length.
Instance Method Summary collapse
-
#cover?(length) ⇒ Boolean
Whether this rule's length band covers the dimension.
-
#initialize(fee_cents:, max_length:, min_length:) ⇒ OverlengthRule
constructor
A new instance of OverlengthRule.
Constructor Details
#initialize(fee_cents:, max_length:, min_length:) ⇒ OverlengthRule
Returns a new instance of OverlengthRule.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/freight_kit/tariff/overlength_rule.rb', line 8 def initialize(fee_cents:, max_length:, min_length:) raise ArgumentError, 'overlength_rule[:fee_cents] must be an Integer' unless fee_cents.is_a?(Integer) if max_length && !max_length.is_a?(Measured::Length) raise ArgumentError, 'overlength_rule[:max_length] must be one of Measured::Length, NilClass' end unless min_length.is_a?(Measured::Length) raise ArgumentError, 'overlength_rule[:min_length] must be a Measured::Length' end @fee_cents = fee_cents @max_length = max_length @min_length = min_length end |
Instance Attribute Details
#fee_cents ⇒ Object (readonly)
Returns the value of attribute fee_cents.
6 7 8 |
# File 'lib/freight_kit/tariff/overlength_rule.rb', line 6 def fee_cents @fee_cents end |
#max_length ⇒ Object (readonly)
Returns the value of attribute max_length.
6 7 8 |
# File 'lib/freight_kit/tariff/overlength_rule.rb', line 6 def max_length @max_length end |
#min_length ⇒ Object (readonly)
Returns the value of attribute min_length.
6 7 8 |
# File 'lib/freight_kit/tariff/overlength_rule.rb', line 6 def min_length @min_length end |
Instance Method Details
#cover?(length) ⇒ Boolean
Returns whether this rule's length band covers the dimension.
26 27 28 29 30 |
# File 'lib/freight_kit/tariff/overlength_rule.rb', line 26 def cover?(length) return false if length < min_length max_length.nil? || length <= max_length end |