Class: Pdf::Label::ItemIdentifier

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/pdf/label/item_identifier.rb

Overview

Service object: item identifier.

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rendererObject (readonly)

Returns the value of attribute renderer.



13
14
15
# File 'app/services/pdf/label/item_identifier.rb', line 13

def renderer
  @renderer
end

Class Method Details

.callObject



9
10
11
# File 'app/services/pdf/label/item_identifier.rb', line 9

def self.call(...)
  new.call(...)
end

.target_market_options_for_selectObject



32
33
34
# File 'app/services/pdf/label/item_identifier.rb', line 32

def self.target_market_options_for_select
  [['USA and Canada', 'usa_canada'], ['Europe', 'europe']]
end

Instance Method Details

#call(item, options = {}) ⇒ Object



26
27
28
29
30
# File 'app/services/pdf/label/item_identifier.rb', line 26

def call(item, options = {})
  Pdf::Loader.load!
  pdf = options[:size] == 'large' ? add_item_page_large(item, options) : add_item_page(item, options)
  Result.new(pdf:, item:, file_name: file_name(item))
end

#country_address_key(item) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'app/services/pdf/label/item_identifier.rb', line 15

def country_address_key(item)
  # Ideally we use store item to print these labels, but since right now it is item based, we will use a simple check
  # If the sku starts with IPE- or TWE- then its a EU item otherwise its a USA item
  # TODO, adapt code so we can do something like @store.country_iso3.downcase.to_sym in the future
  if item.sku.start_with?('IPE-', 'TWE-')
    :nld
  else
    :usa
  end
end