Module: Peddler::Acronyms

Extended by:
Acronyms
Included in:
Acronyms
Defined in:
lib/peddler/acronyms.rb

Overview

Handles acronym transformations for Amazon SP-API terminology

Constant Summary collapse

MAP =

Mapping of camelized forms to their uppercase acronym equivalents

{
  "Api" => "API",
  "Asin" => "ASIN",
  "B2b" => "B2B",
  "Cgst" => "CGST",
  "Cod" => "COD",
  "Fba" => "FBA",
  "Igst" => "IGST",
  "Lwa" => "LWA",
  "Safet" => "SAFET",
  "Sgst" => "SGST",
  "Sku" => "SKU",
  "Tds" => "TDS",
  "Url" => "URL",
}.freeze

Instance Method Summary collapse

Instance Method Details

#apply(word) ⇒ String

Transforms acronyms in camelized words to uppercase equivalents. Uses lookahead to prevent partial matches within words (e.g., "Cod" won't match inside "Code"). Handles singular and plural forms (e.g., "Apis" to "APIs").

Parameters:

  • word (String)

Returns:

  • (String)


30
31
32
# File 'lib/peddler/acronyms.rb', line 30

def apply(word)
  MAP.reduce(word) { |w, (from, to)| w.gsub(/#{from}(s?)(?=[A-Z]|$)/) { "#{to}#{::Regexp.last_match(1)}" } }
end

#valuesArray<String>

Returns Array of uppercase acronyms.

Returns:

  • (Array<String>)

    Array of uppercase acronyms



35
36
37
# File 'lib/peddler/acronyms.rb', line 35

def values
  MAP.values
end