Class: Completely::Pattern
- Inherits:
-
Object
- Object
- Completely::Pattern
- Defined in:
- lib/completely/pattern.rb
Instance Attribute Summary collapse
-
#completions ⇒ Object
readonly
Returns the value of attribute completions.
-
#function_name ⇒ Object
readonly
Returns the value of attribute function_name.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #actions ⇒ Object
- #case_string ⇒ Object
- #compgen ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(text, completions, function_name) ⇒ Pattern
constructor
A new instance of Pattern.
- #length ⇒ Object
- #prefix ⇒ Object
- #text_without_prefix ⇒ Object
- #words ⇒ Object
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
#completions ⇒ Object (readonly)
Returns the value of attribute completions.
3 4 5 |
# File 'lib/completely/pattern.rb', line 3 def completions @completions end |
#function_name ⇒ Object (readonly)
Returns the value of attribute function_name.
3 4 5 |
# File 'lib/completely/pattern.rb', line 3 def function_name @function_name end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
3 4 5 |
# File 'lib/completely/pattern.rb', line 3 def text @text end |
Instance Method Details
#actions ⇒ Object
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_string ⇒ Object
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 |
#compgen ⇒ Object
48 49 50 |
# File 'lib/completely/pattern.rb', line 48 def compgen @compgen ||= compgen! end |
#empty? ⇒ Boolean
15 16 17 |
# File 'lib/completely/pattern.rb', line 15 def empty? completions.empty? end |
#length ⇒ Object
11 12 13 |
# File 'lib/completely/pattern.rb', line 11 def length @length ||= text.size end |
#prefix ⇒ Object
30 31 32 |
# File 'lib/completely/pattern.rb', line 30 def prefix text.split(/ |\*/).first end |
#text_without_prefix ⇒ Object
44 45 46 |
# File 'lib/completely/pattern.rb', line 44 def text_without_prefix @text_without_prefix ||= text[/^#{prefix}\s*(.*)/, 1] end |
#words ⇒ Object
19 20 21 |
# File 'lib/completely/pattern.rb', line 19 def words @words ||= completions.grep_v(/^<.*>$/) end |