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



40
41
42
# File 'app/services/pdf/label/item_identifier.rb', line 40

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

Instance Method Details

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

Returns the generated PDF result.

Parameters:

  • item (Item)

    the item to generate the identifier label for

  • options (Hash) (defaults to: {})

    Options hash

Options Hash (options):

  • :size (String)

    label size ('large' selects the large layout)

  • :target_market (String)

    target market ('usa_canada' or 'europe')

  • :serial_number (String)

    serial number to print on the label

  • :amazon_transparency_code (String)

    Amazon transparency code to print

  • :output_amazon_transparency (Boolean)

    render the Amazon transparency section

Returns:

  • (Result)

    the generated PDF result



34
35
36
37
38
# File 'app/services/pdf/label/item_identifier.rb', line 34

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