Class: Edi::ResellerInventory::Renderer

Inherits:
Object
  • Object
show all
Defined in:
app/services/edi/reseller_inventory/renderer.rb

Overview

Renders an inventory-CSV Templates template against a catalog-item scope,
reproducing the legacy Feed#render binding exactly: the template sees
@catalog_items and the ssc (strip-special-characters) helper.

Instance Method Summary collapse

Constructor Details

#initialize(catalog_items) ⇒ Renderer

Returns a new instance of Renderer.

Parameters:



11
12
13
# File 'app/services/edi/reseller_inventory/renderer.rb', line 11

def initialize(catalog_items)
  @catalog_items = catalog_items
end

Instance Method Details

#render(template_erb) ⇒ String

Returns the rendered CSV.

Parameters:

  • template_erb (String)

Returns:

  • (String)

    the rendered CSV.



17
18
19
# File 'app/services/edi/reseller_inventory/renderer.rb', line 17

def render(template_erb)
  ERB.new(template_erb).result(binding)
end

#ssc(str) ⇒ Object

Strip special characters — byte-for-byte parity with the legacy Feed#ssc:
keeps alphanumerics, . and /; everything else (including -) becomes a
space, then whitespace is squished.



24
25
26
# File 'app/services/edi/reseller_inventory/renderer.rb', line 24

def ssc(str)
  str.to_s.gsub(%r{[^0-9A-Za-z./]}, ' ').squish
end