Class: Architext::SelectionParser

Inherits:
Object
  • Object
show all
Defined in:
lib/architext/selection_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(paths) ⇒ SelectionParser

Returns a new instance of SelectionParser.



5
6
7
# File 'lib/architext/selection_parser.rb', line 5

def initialize(paths)
  @paths = paths
end

Instance Method Details

#parse(input) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/architext/selection_parser.rb', line 9

def parse(input)
  normalized = input.to_s.strip.downcase
  return @paths if %w[a all *].include?(normalized)
  return [] if normalized.empty?

  indexes = normalized.split(',').flat_map { |part| expand_part(part.strip) }
  indexes.uniq.filter_map { |index| @paths[index - 1] }
end