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.
-
#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) ⇒ Pattern
constructor
A new instance of Pattern.
- #length ⇒ Object
- #prefix ⇒ Object
- #text_without_prefix ⇒ Object
- #words ⇒ Object
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
#completions ⇒ Object (readonly)
Returns the value of attribute completions.
3 4 5 |
# File 'lib/completely/pattern.rb', line 3 def completions @completions 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
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_string ⇒ Object
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 |
#compgen ⇒ Object
47 48 49 |
# File 'lib/completely/pattern.rb', line 47 def compgen @compgen ||= compgen! end |
#empty? ⇒ Boolean
14 15 16 |
# File 'lib/completely/pattern.rb', line 14 def empty? completions.empty? end |
#length ⇒ Object
10 11 12 |
# File 'lib/completely/pattern.rb', line 10 def length @length ||= text.size end |
#prefix ⇒ Object
29 30 31 |
# File 'lib/completely/pattern.rb', line 29 def prefix text.split(' ')[0] end |
#text_without_prefix ⇒ Object
43 44 45 |
# File 'lib/completely/pattern.rb', line 43 def text_without_prefix @text_without_prefix ||= text.split(' ')[1..-1].join ' ' end |
#words ⇒ Object
18 19 20 |
# File 'lib/completely/pattern.rb', line 18 def words @words ||= completions.reject { |w| w =~ /^<.*>$/ } end |