Class: Command::CompletionsLister

Inherits:
SetVisitor show all
Defined in:
lib/command-set/structural.rb

Instance Attribute Summary collapse

Attributes inherited from SetVisitor

#command_path, #subject_context

Instance Method Summary collapse

Methods inherited from SetVisitor

#extra_terms, #leave_from

Constructor Details

#initialize(prefix, subject, terms) ⇒ CompletionsLister

Returns a new instance of CompletionsLister.



126
127
128
129
130
131
132
133
# File 'lib/command-set/structural.rb', line 126

def initialize(prefix, subject, terms)
  super()
  @prefix = prefix 
  @subject = subject
  @completion_list = []
  @arguments = []
  @original_terms = terms.dup
end

Instance Attribute Details

#completion_listObject (readonly)

Returns the value of attribute completion_list.



135
136
137
# File 'lib/command-set/structural.rb', line 135

def completion_list
  @completion_list
end

#prefixObject (readonly)

Returns the value of attribute prefix.



135
136
137
# File 'lib/command-set/structural.rb', line 135

def prefix
  @prefix
end

#subjectObject (readonly)

Returns the value of attribute subject.



135
136
137
# File 'lib/command-set/structural.rb', line 135

def subject
  @subject
end

Instance Method Details

#arrive_at(terms, node) ⇒ Object



137
138
139
140
141
142
143
# File 'lib/command-set/structural.rb', line 137

def arrive_at(terms, node)
  @arguments = node.argument_list.dup
  image = subject.get_image(node.subject_requirements)
  until terms.empty? or @arguments.empty? do
    @arguments.first.match_terms(image, terms, @arguments)
  end
end

#command_out_of_terms(node) ⇒ Object



151
152
153
154
155
156
157
# File 'lib/command-set/structural.rb', line 151

def command_out_of_terms(node)
  image = @subject.get_image(node.subject_requirements)
  @arguments.each do |handler|
    @completion_list += handler.complete(@original_terms, @prefix, image)
    break unless handler.omittable?
  end 
end

#set_out_of_terms(node) ⇒ Object



145
146
147
148
149
# File 'lib/command-set/structural.rb', line 145

def set_out_of_terms(node)
  if @arguments.empty? or not @arguments.first.required?
    @completion_list = node.command_names.grep(%r{^#{prefix}.*})
  end
end

#term_without_hop(terms, node) ⇒ Object



159
160
161
# File 'lib/command-set/structural.rb', line 159

def term_without_hop(terms, node)
  return []
end