Class: AssetFinder::Javascript::Normalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/asset_finder/javascript/normalizer.rb

Instance Method Summary collapse

Constructor Details

#initialize(root_dir:, path_pattern_collection:, normalize_index_file: true) ⇒ Normalizer

Returns a new instance of Normalizer.



4
5
6
7
8
9
10
# File 'lib/asset_finder/javascript/normalizer.rb', line 4

def initialize(root_dir:, path_pattern_collection:, normalize_index_file: true)
  @root_dir = root_dir.to_s
  @path_pattern_collection = path_pattern_collection
  @normalize_index_file = normalize_index_file

  freeze
end

Instance Method Details

#normalize(path) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/asset_finder/javascript/normalizer.rb', line 12

def normalize(path)
  match = path_pattern_collection.match(path: path)
  return unless match

  normalized_path = match[1].delete_prefix(root_dir)
  normalized_path = normalized_path.delete_suffix('/index') if normalize_index_file
  normalized_path + '.js'
end