Class: VolumePrice
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- VolumePrice
- Defined in:
- app/models/volume_price.rb
Constant Summary collapse
- OPEN_ENDED =
/\([0-9]+\+\)/
Instance Method Summary collapse
- #include?(quantity) ⇒ Boolean
-
#open_ended? ⇒ Boolean
indicates whether or not the range is a true Ruby range or an open ended range with no upper bound.
- #validate ⇒ Object
Instance Method Details
#include?(quantity) ⇒ Boolean
14 15 16 17 18 19 20 21 |
# File 'app/models/volume_price.rb', line 14 def include?(quantity) if open_ended? bound = /\d+/.match(range)[0].to_i return quantity >= bound else range.to_range === quantity end end |
#open_ended? ⇒ Boolean
indicates whether or not the range is a true Ruby range or an open ended range with no upper bound
24 25 26 |
# File 'app/models/volume_price.rb', line 24 def open_ended? OPEN_ENDED =~ range end |
#validate ⇒ Object
9 10 11 12 |
# File 'app/models/volume_price.rb', line 9 def validate return if open_ended? errors.add(:range, "must be in one of the following formats: (a..b), (a...b), (a+)") unless /\([0-9]+\.{2,3}[0-9]+\)/ =~ range end |