Sha256: e8bda7a37d0688b1d1f9646e12222aeed8e90a2c35c379f09d434c37632efa4b
Contents?: true
Size: 1.08 KB
Versions: 4
Compression:
Stored size: 1.08 KB
Contents
class Spree::VolumePrice < ActiveRecord::Base belongs_to :variant, touch: true belongs_to :volume_price_model, touch: true belongs_to :spree_role, class_name: 'Spree::Role', foreign_key: 'role_id' acts_as_list scope: [:variant_id, :volume_price_model_id] validates :amount, presence: true validates :discount_type, presence: true, inclusion: { in: %w(price dollar percent), message: I18n.t(:'activerecord.errors.messages.is_not_a_valid_volume_price_type', value: self) } validates :range, format: { with: /\(?[0-9]+(?:\.{2,3}[0-9]+|\+\)?)/, message: I18n.t(:'activerecord.errors.messages.must_be_in_format') } OPEN_ENDED = /\(?[0-9]+\+\)?/ def include?(quantity) if open_ended? bound = /\d+/.match(range)[0].to_i return quantity >= bound else range.to_range === quantity end end # indicates whether or not the range is a true Ruby range or an open ended range with no upper bound def open_ended? OPEN_ENDED =~ range end end
Version data entries
4 entries across 4 versions & 1 rubygems