Class: Workarea::Pricing::Collection
- Inherits:
-
Object
- Object
- Workarea::Pricing::Collection
- Includes:
- Enumerable
- Defined in:
- app/models/workarea/pricing/collection.rb
Instance Attribute Summary collapse
-
#skus ⇒ Object
readonly
Returns the value of attribute skus.
Instance Method Summary collapse
- #all_selling_prices ⇒ Object
- #for_sku(sku, options = {}) ⇒ Object
- #has_prices? ⇒ Boolean
-
#initialize(skus, records = nil) ⇒ Collection
constructor
A new instance of Collection.
- #msrp_max_price ⇒ Object
- #msrp_min_price ⇒ Object
- #on_sale? ⇒ Boolean
- #records ⇒ Object
- #regular_max_price ⇒ Object
- #regular_min_price ⇒ Object
- #sale_max_price ⇒ Object
- #sale_min_price ⇒ Object
- #sell_max_price ⇒ Object
- #sell_min_price ⇒ Object
Constructor Details
#initialize(skus, records = nil) ⇒ Collection
Returns a new instance of Collection.
8 9 10 11 |
# File 'app/models/workarea/pricing/collection.rb', line 8 def initialize(skus, records = nil) @skus = Array(skus) @records = records end |
Instance Attribute Details
#skus ⇒ Object (readonly)
Returns the value of attribute skus.
5 6 7 |
# File 'app/models/workarea/pricing/collection.rb', line 5 def skus @skus end |
Instance Method Details
#all_selling_prices ⇒ Object
18 19 20 21 |
# File 'app/models/workarea/pricing/collection.rb', line 18 def all_selling_prices return @all_selling_prices if defined?(@all_selling_prices) @all_selling_prices = generic_prices.map(&:sell).compact end |
#for_sku(sku, options = {}) ⇒ Object
13 14 15 16 |
# File 'app/models/workarea/pricing/collection.rb', line 13 def for_sku(sku, = {}) sku = records.detect { |r| r.id == sku } || Sku.new(id: sku) sku.find_price() end |
#has_prices? ⇒ Boolean
68 69 70 71 |
# File 'app/models/workarea/pricing/collection.rb', line 68 def has_prices? return !!@has_prices if defined?(@has_prices) @has_prices = generic_prices.any? end |
#msrp_max_price ⇒ Object
58 59 60 61 |
# File 'app/models/workarea/pricing/collection.rb', line 58 def msrp_max_price return @msrp_max_price if defined?(@msrp_max_price) @msrp_max_price = records.map(&:msrp).compact.sort.last end |
#msrp_min_price ⇒ Object
53 54 55 56 |
# File 'app/models/workarea/pricing/collection.rb', line 53 def msrp_min_price return @msrp_min_price if defined?(@msrp_min_price) @msrp_min_price = records.map(&:msrp).compact.sort.first end |
#on_sale? ⇒ Boolean
63 64 65 66 |
# File 'app/models/workarea/pricing/collection.rb', line 63 def on_sale? return !!@on_sale if defined?(@on_sale) @on_sale = generic_prices.any?(&:on_sale?) end |
#records ⇒ Object
73 74 75 |
# File 'app/models/workarea/pricing/collection.rb', line 73 def records @records ||= Sku.where(:_id.in => skus).to_a end |
#regular_max_price ⇒ Object
28 29 30 31 |
# File 'app/models/workarea/pricing/collection.rb', line 28 def regular_max_price return @regular_max_price if defined?(@regular_max_price) @regular_max_price = generic_prices.map(&:regular).sort.last end |
#regular_min_price ⇒ Object
23 24 25 26 |
# File 'app/models/workarea/pricing/collection.rb', line 23 def regular_min_price return @regular_min_price if defined?(@regular_min_price) @regular_min_price = generic_prices.map(&:regular).sort.first end |
#sale_max_price ⇒ Object
38 39 40 41 |
# File 'app/models/workarea/pricing/collection.rb', line 38 def sale_max_price return @sale_max_price if defined?(@sale_max_price) @sale_max_price = generic_prices.map(&:sale).compact.sort.last end |
#sale_min_price ⇒ Object
33 34 35 36 |
# File 'app/models/workarea/pricing/collection.rb', line 33 def sale_min_price return @sale_min_price if defined?(@sale_min_price) @sale_min_price = generic_prices.map(&:sale).compact.sort.first end |
#sell_max_price ⇒ Object
48 49 50 51 |
# File 'app/models/workarea/pricing/collection.rb', line 48 def sell_max_price return @sell_max_price if defined?(@sell_max_price) @sell_max_price = generic_prices.map(&:sell).sort.last end |
#sell_min_price ⇒ Object
43 44 45 46 |
# File 'app/models/workarea/pricing/collection.rb', line 43 def sell_min_price return @sell_min_price if defined?(@sell_min_price) @sell_min_price = generic_prices.map(&:sell).sort.first end |