Module: Prompt::DSLHelper

Defined in:
lib/prompt/dsl_helper.rb

Class Method Summary collapse

Class Method Details

.find_param(word, parameters) ⇒ Object



22
23
24
25
# File 'lib/prompt/dsl_helper.rb', line 22

def self.find_param word, parameters
  sym = word[1..-1].to_sym
  parameters.find {|p| p.name == sym} || Parameter.new(sym)
end

.words(command_name, parameters) ⇒ Object

Split command into an array of Strings and Matchers



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/prompt/dsl_helper.rb', line 8

def self.words command_name, parameters
  command_name.strip.split(/\s+/).map do |word|
    if word[0] == ":"
      param = find_param word, parameters
      SimpleMatcher.new param
    elsif word[0] == "*"
      param = find_param word, parameters
      MultiMatcher.new param
    else
      word
    end
  end
end