Class: PathParserService

Inherits:
Object
  • Object
show all
Defined in:
app/services/path_parser_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(template, path) ⇒ PathParserService

Returns a new instance of PathParserService.



2
3
4
5
# File 'app/services/path_parser_service.rb', line 2

def initialize(template, path)
  @template = template
  @path = path
end

Instance Method Details

#call ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'app/services/path_parser_service.rb', line 7

def call
  components = @path.match(path_parse_pattern)&.named_captures&.symbolize_keys
  return {} if components.nil?
  components.merge({
    tags: components[:tags]&.split(File::SEPARATOR)&.compact_blank,
    collections: components[:collection] ? [components.delete(:collection)] : components[:collections]&.split("/")&.compact_blank,
    model_id: nil # discard ID, never gonna use it in parsing
  }).compact_blank
end