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) ⇒ Pattern

Returns a new instance of Pattern.



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

def initialize(text, completions)
  @text = text
  @completions = completions || []
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

#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



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

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

#case_stringObject



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

def case_string
  if text_without_prefix.empty?
    "*"
  elsif text_without_prefix.include? "*" 
    %Q['#{text_without_prefix.gsub "*", "'*'"}']
  else
    %Q['#{text_without_prefix}'*]
  end
end

#compgenObject



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

def compgen
  @compgen ||= compgen!
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  completions.empty?
end

#lengthObject



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

def length
  @length ||= text.size
end

#prefixObject



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

def prefix
  text.split(' ')[0]
end

#text_without_prefixObject



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

def text_without_prefix
  @text_without_prefix ||= text.split(' ')[1..-1].join ' '
end

#wordsObject



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

def words
  @words ||= completions.reject { |w| w =~ /^<.*>$/ }
end