Module: TieredCategoryExpressions::Preprocessor

Defined in:
lib/tiered_category_expressions/preprocessor.rb

Class Method Summary collapse

Class Method Details

.call(category) ⇒ String

Converts a category to a string suitable for matching with TCE regexps.

Examples:

category = ["Non-food", "Cosmetics"]
preprocessed_category = TieredCategoryExpressions::Preprocessor.call(category)
TCE("nonfood > cosmetics").to_regexp.match?(preprocessed_category)
# => true

Parameters:

  • category (Array<String>)

Returns:

  • (String)


18
19
20
21
22
# File 'lib/tiered_category_expressions/preprocessor.rb', line 18

def call(category)
  return "" if category.empty?

  category.map { |t| sanitize_name(t) }.join(">") + ">"
end