Class: Appydave::Tools::Dam::BrandResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/appydave/tools/dam/brand_resolver.rb

Overview

Centralized brand name resolution and transformation

Handles conversion between:

  • Shortcuts: ‘appydave’, ‘ad’, ‘joy’, ‘ss’

  • Config keys: ‘appydave’, ‘beauty-and-joy’, ‘supportsignal’

  • Display names: ‘v-appydave’, ‘v-beauty-and-joy’, ‘v-supportsignal’

Examples:

BrandResolver.expand('ad')          # => 'v-appydave'
BrandResolver.normalize('v-voz')    # => 'voz'
BrandResolver.to_config_key('ad')   # => 'appydave'
BrandResolver.to_display('voz')     # => 'v-voz'

Class Method Summary collapse

Class Method Details

.exists?(brand) ⇒ Boolean

Check if brand exists (returns boolean instead of raising)

Parameters:

  • brand (String)

    Brand to check

Returns:

  • (Boolean)

    true if brand exists



114
115
116
117
118
119
# File 'lib/appydave/tools/dam/brand_resolver.rb', line 114

def exists?(brand)
  validate(brand)
  true
rescue BrandNotFoundError
  false
end

.expand(shortcut) ⇒ String

Expand shortcut or key to full display name

Parameters:

  • shortcut (String)

    Brand shortcut or key

Returns:

  • (String)

    Full brand name with v- prefix



23
24
25
26
27
28
# File 'lib/appydave/tools/dam/brand_resolver.rb', line 23

def expand(shortcut)
  return shortcut.to_s if shortcut.to_s.start_with?('v-')

  key = to_config_key(shortcut)
  "v-#{key}"
end

.normalize(brand) ⇒ String

Normalize brand name to config key (strip v- prefix)

Parameters:

  • brand (String)

    Brand name (with or without v-)

Returns:

  • (String)

    Config key without v- prefix



33
34
35
# File 'lib/appydave/tools/dam/brand_resolver.rb', line 33

def normalize(brand)
  brand.to_s.sub(/^v-/, '')
end

.to_config_key(input) ⇒ String

Convert to config key (handles shortcuts)

Parameters:

  • input (String)

    Shortcut, key, or display name

Returns:

  • (String)

    Config key



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/appydave/tools/dam/brand_resolver.rb', line 40

def to_config_key(input)
  # Strip v- prefix first
  normalized = normalize(input)

  # Look up from brands.json
  Appydave::Tools::Configuration::Config.configure
  brands_config = Appydave::Tools::Configuration::Config.brands

  # Check if matches brand key (case-insensitive)
  brand = brands_config.brands.find { |b| b.key.downcase == normalized.downcase }
  return brand.key if brand

  # Check if matches shortcut (case-insensitive)
  brand = brands_config.brands.find { |b| b.shortcut.downcase == normalized.downcase }
  return brand.key if brand

  # Fall back to hardcoded shortcuts (backward compatibility)
  case normalized.downcase
  when 'ad' then 'appydave'
  when 'joy' then 'beauty-and-joy'
  when 'ss' then 'supportsignal'
  else
    normalized.downcase
  end
end

.to_display(input) ⇒ String

Convert to display name (always v- prefix)

Parameters:

  • input (String)

    Shortcut, key, or display name

Returns:

  • (String)

    Display name with v- prefix



69
70
71
# File 'lib/appydave/tools/dam/brand_resolver.rb', line 69

def to_display(input)
  expand(input)
end

.validate(brand) ⇒ String

Validate brand exists in filesystem

Parameters:

  • brand (String)

    Brand to validate

Returns:

  • (String)

    Config key if valid

Raises:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/appydave/tools/dam/brand_resolver.rb', line 77

def validate(brand)
  key = to_config_key(brand)

  # Build brand path (avoiding circular dependency with Config.brand_path)
  Appydave::Tools::Configuration::Config.configure
  brand_info = Appydave::Tools::Configuration::Config.brands.get_brand(key)

  # If brand has configured video_projects path, use it
  if brand_info.locations.video_projects && !brand_info.locations.video_projects.empty?
    brand_path = brand_info.locations.video_projects
  else
    # Fall back to projects_root + expanded brand name
    root = Config.projects_root
    brand_path = File.join(root, expand(key))
  end

  unless Dir.exist?(brand_path)
    # Get available brands for error message
    available = Config.available_brands_display

    # Use fuzzy matching to suggest similar brands
    available_list = Config.available_brands
    suggestions = FuzzyMatcher.find_matches(brand, available_list, threshold: 3)

    raise BrandNotFoundError.new(brand, available, suggestions)
  end

  key
rescue StandardError => e
  raise BrandNotFoundError, e.message unless e.is_a?(BrandNotFoundError)

  raise
end