Class: ItemBuilderMwh::Modes::SimpleService

Inherits:
Object
  • Object
show all
Includes:
ItemBuilderMwh::Modes
Defined in:
lib/item_builder_mwh/modes/simple_service.rb

Constant Summary collapse

QUANTITY_CHANNEL =
{}.tap do |hash|
  hash[3]       = :Lazada
  hash[9]       = :Blibli
  hash[12]      = :Shopee
  hash[13]      = :Zalora
end.freeze
PRICE_CHANNEL =
{}.tap do |hash|
  hash[2]       = :Shopify
  hash[9]       = :Blibli
  hash[11]      = :Bukalapak
  hash[13]      = :Zalora
  hash[16]      = :Jd
end.freeze

Instance Attribute Summary

Attributes included from ItemBuilderMwh::Modes

#listing

Instance Method Summary collapse

Methods included from ItemBuilderMwh::Modes

#base, #initialize, #pca, #warehouse, #warehouse_mapping, #warehouse_spaces, #warehouses, #wh_mapping

Instance Method Details

#performObject



32
33
34
35
36
# File 'lib/item_builder_mwh/modes/simple_service.rb', line 32

def perform
  base.merge!(
    warehouse: warehouses
  )
end

#priceObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/item_builder_mwh/modes/simple_service.rb', line 71

def price
  if price_name.empty?
    {
      price: listing.price,
      sale_price: listing.sale_price,
      sale_start_at: listing.sale_start_at,
      sale_end_at: listing.sale_end_at
    }
  else
    price_channel
  end
end

#price_channelObject



84
85
86
87
88
# File 'lib/item_builder_mwh/modes/simple_service.rb', line 84

def price_channel
  class_name = "ItemBuilderMwh::Modes::Price::#{price_name}Service"
  simple_channel_service = class_name.constantize
  simple_channel_service.new(listing, available_qty).perform
end

#price_nameObject



96
97
98
# File 'lib/item_builder_mwh/modes/simple_service.rb', line 96

def price_name
  PRICE_CHANNEL[listing.channel_id].to_s
end

#qty(available_qty) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/item_builder_mwh/modes/simple_service.rb', line 59

def qty(available_qty)
  if quantity_name.empty?
    {
      quantity: available_qty
    }
  else
    {
      quantity: qty_channel(available_qty)
    }
  end
end

#qty_channel(available_qty) ⇒ Object



90
91
92
93
94
# File 'lib/item_builder_mwh/modes/simple_service.rb', line 90

def qty_channel(available_qty)
  class_name = "ItemBuilderMwh::Modes::Quantity::#{quantity_name}Service"
  qty_channel_service = class_name.constantize
  qty_channel_service.new(listing, available_qty).perform
end

#quantity_nameObject



100
101
102
# File 'lib/item_builder_mwh/modes/simple_service.rb', line 100

def quantity_name
  QUANTITY_CHANNEL[listing.channel_id].to_s
end

#simple(warehouse_space) ⇒ Object



52
53
54
55
56
57
# File 'lib/item_builder_mwh/modes/simple_service.rb', line 52

def simple(warehouse_space)
  available_qty = warehouse_space.quantity
  qty(available_qty).merge(
    price
  )
end

#to_h(warehouse_space) ⇒ Object



38
39
40
41
42
# File 'lib/item_builder_mwh/modes/simple_service.rb', line 38

def to_h(warehouse_space)
  warehouse_ids(warehouse_space).merge(
    simple(warehouse_space)
  )
end

#warehouse_ids(warehouse_space) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/item_builder_mwh/modes/simple_service.rb', line 44

def warehouse_ids(warehouse_space)
  {
    warehouse_id: wh_mapping(
      warehouse_space.warehouse_id
    )
  }
end