Class: BBMB::Model::ProductInfo
- Includes:
- Util::Numbers
- Defined in:
- lib/bbmb/model/product.rb,
lib/bbmb/persistence/odba/model/product.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#article_number ⇒ Object
readonly
Returns the value of attribute article_number.
-
#backorder ⇒ Object
readonly
Returns the value of attribute backorder.
-
#backorder_date ⇒ Object
Returns the value of attribute backorder_date.
-
#commit_date ⇒ Object
Returns the value of attribute commit_date.
-
#ean13 ⇒ Object
Returns the value of attribute ean13.
-
#expiry_date ⇒ Object
Returns the value of attribute expiry_date.
-
#partner_index ⇒ Object
Returns the value of attribute partner_index.
-
#pcode ⇒ Object
Returns the value of attribute pcode.
-
#promotion ⇒ Object
Returns the value of attribute promotion.
-
#sale ⇒ Object
Returns the value of attribute sale.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #current_promo ⇒ Object
- #freebies(level) ⇒ Object
-
#initialize(article_number) ⇒ ProductInfo
constructor
A new instance of ProductInfo.
- #migrate_to_subject ⇒ Object
- #price(qty = nil) ⇒ Object
- #price_base ⇒ Object
- #price_effective(qty = nil) ⇒ Object
- #price_qty(qty = nil) ⇒ Object
- #qty_level(level = nil) ⇒ Object
- #to_info ⇒ Object
Methods included from Util::Numbers
Methods inherited from Subject
Constructor Details
#initialize(article_number) ⇒ ProductInfo
Returns a new instance of ProductInfo.
19 20 21 22 |
# File 'lib/bbmb/model/product.rb', line 19 def initialize(article_number) @article_number = article_number @backorder = false end |
Instance Attribute Details
#article_number ⇒ Object (readonly)
Returns the value of attribute article_number.
12 13 14 |
# File 'lib/bbmb/model/product.rb', line 12 def article_number @article_number end |
#backorder ⇒ Object (readonly)
Returns the value of attribute backorder.
12 13 14 |
# File 'lib/bbmb/model/product.rb', line 12 def backorder @backorder end |
#backorder_date ⇒ Object
Returns the value of attribute backorder_date.
13 14 15 |
# File 'lib/bbmb/model/product.rb', line 13 def backorder_date @backorder_date end |
#commit_date ⇒ Object
Returns the value of attribute commit_date.
13 14 15 |
# File 'lib/bbmb/model/product.rb', line 13 def commit_date @commit_date end |
#ean13 ⇒ Object
Returns the value of attribute ean13.
13 14 15 |
# File 'lib/bbmb/model/product.rb', line 13 def ean13 @ean13 end |
#expiry_date ⇒ Object
Returns the value of attribute expiry_date.
13 14 15 |
# File 'lib/bbmb/model/product.rb', line 13 def expiry_date @expiry_date end |
#partner_index ⇒ Object
Returns the value of attribute partner_index.
13 14 15 |
# File 'lib/bbmb/model/product.rb', line 13 def partner_index @partner_index end |
#pcode ⇒ Object
Returns the value of attribute pcode.
13 14 15 |
# File 'lib/bbmb/model/product.rb', line 13 def pcode @pcode end |
#promotion ⇒ Object
Returns the value of attribute promotion.
13 14 15 |
# File 'lib/bbmb/model/product.rb', line 13 def promotion @promotion end |
#sale ⇒ Object
Returns the value of attribute sale.
13 14 15 |
# File 'lib/bbmb/model/product.rb', line 13 def sale @sale end |
#status ⇒ Object
Returns the value of attribute status.
13 14 15 |
# File 'lib/bbmb/model/product.rb', line 13 def status @status end |
Instance Method Details
#==(other) ⇒ Object
68 69 70 |
# File 'lib/bbmb/model/product.rb', line 68 def ==(other) other.is_a?(ProductInfo) && @article_number == other.article_number end |
#current_promo ⇒ Object
23 24 25 |
# File 'lib/bbmb/model/product.rb', line 23 def current_promo [@sale, @promotion].find { |promo| promo } end |
#freebies(level) ⇒ Object
26 27 28 |
# File 'lib/bbmb/model/product.rb', line 26 def freebies(level) (promo = current_promo) && promo.freebies(level) end |
#migrate_to_subject ⇒ Object
9 10 11 12 13 14 |
# File 'lib/bbmb/persistence/odba/model/product.rb', line 9 def migrate_to_subject changed = super @promotion && @promotion.migrate_to_subject && (changed = true) @sale && @sale.migrate_to_subject && (changed = true) changed end |
#price(qty = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bbmb/model/product.rb', line 29 def price(qty=nil) qty ||= 1 res = @price (1..6).each { |num| if(res.nil? || ((tmp = instance_variable_get("@l#{num}_qty")) \ && qty >= tmp)) res = instance_variable_get("@l#{num}_price") || res end } if((pr = current_promo) && (((price = pr.price_qty(qty)) && price > res) \ || ((price = pr.l1_price) && price > res))) res = price end res end |
#price_base ⇒ Object
44 45 46 |
# File 'lib/bbmb/model/product.rb', line 44 def price_base price(1) end |
#price_effective(qty = nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/bbmb/model/product.rb', line 47 def price_effective(qty=nil) price = price_qty(qty) if((promo = current_promo) && (discount = promo.discount(qty))) price *= (100.0 - discount) / 100.0 end price || Util::Money.new(0) end |
#price_qty(qty = nil) ⇒ Object
54 55 56 57 |
# File 'lib/bbmb/model/product.rb', line 54 def price_qty(qty=nil) ((promo = current_promo) && promo.price_qty(qty)) \ || price(qty) end |
#qty_level(level = nil) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/bbmb/model/product.rb', line 58 def qty_level(level=nil) if((promo = current_promo) && promo.has_price_qty?) promo.qty_level(level) else instance_variable_get("@l#{level}_qty") end end |
#to_info ⇒ Object
65 66 67 |
# File 'lib/bbmb/model/product.rb', line 65 def to_info self end |