Class: Workarea::Pricing::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
app/models/workarea/pricing/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#skusObject (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_pricesObject



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, options = {})
  sku = records.detect { |r| r.id == sku } || Sku.new(id: sku)
  sku.find_price(options)
end

#has_prices?Boolean

Returns:

  • (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_priceObject



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_priceObject



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

Returns:

  • (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

#recordsObject



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_priceObject



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_priceObject



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_priceObject



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_priceObject



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_priceObject



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_priceObject



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