Module: Peddler::Acronyms
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
-
#apply(word) ⇒ String
Transforms acronyms in camelized words to uppercase equivalents.
-
#values ⇒ Array<String>
Array of uppercase acronyms.
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").
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 |
#values ⇒ Array<String>
Returns Array of uppercase acronyms.
35 36 37 |
# File 'lib/peddler/acronyms.rb', line 35 def values MAP.values end |