Class: Completely::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/completely/pattern.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, completions, function_name) ⇒ Pattern

Returns a new instance of Pattern.



5
6
7
8
9
# File 'lib/completely/pattern.rb', line 5

def initialize(text, completions, function_name)
  @text = text
  @completions = completions || []
  @function_name = function_name
end

Instance Attribute Details

#completionsObject (readonly)

Returns the value of attribute completions.



3
4
5
# File 'lib/completely/pattern.rb', line 3

def completions
  @completions
end

#function_nameObject (readonly)

Returns the value of attribute function_name.



3
4
5
# File 'lib/completely/pattern.rb', line 3

def function_name
  @function_name
end

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/completely/pattern.rb', line 3

def text
  @text
end

Instance Method Details

#actionsObject



23
24
25
26
27
28
# File 'lib/completely/pattern.rb', line 23

def actions
  @actions ||= completions.filter_map do |word|
    action = word[/^<(.+)>$/, 1]
    "-A #{action}" if action
  end
end

#case_stringObject



34
35
36
37
38
39
40
41
42
# File 'lib/completely/pattern.rb', line 34

def case_string
  if text_without_prefix.empty?
    '*'
  elsif text_without_prefix.include? '*'
    text_without_prefix.gsub(/([^*]+)/, "'\\1'")
  else
    "'#{text_without_prefix}'*"
  end
end

#compgenObject



48
49
50
# File 'lib/completely/pattern.rb', line 48

def compgen
  @compgen ||= compgen!
end

#empty?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/completely/pattern.rb', line 15

def empty?
  completions.empty?
end

#lengthObject



11
12
13
# File 'lib/completely/pattern.rb', line 11

def length
  @length ||= text.size
end

#prefixObject



30
31
32
# File 'lib/completely/pattern.rb', line 30

def prefix
  text.split(/ |\*/).first
end

#text_without_prefixObject



44
45
46
# File 'lib/completely/pattern.rb', line 44

def text_without_prefix
  @text_without_prefix ||= text[/^#{prefix}\s*(.*)/, 1]
end

#wordsObject



19
20
21
# File 'lib/completely/pattern.rb', line 19

def words
  @words ||= completions.grep_v(/^<.*>$/)
end