Class: Ruber::IRB::PromptMatcher
- Inherits:
-
Object
- Object
- Ruber::IRB::PromptMatcher
- Defined in:
- plugins/irb/irb_controller.rb
Overview
Incapsulates the information about the special prompt used by the plugin
Constant Summary
- MODES =
Mapping between mode names and characters used in the prompt
{'n' => :normal, 's' => :string, 'c' => :statement, 'i' => :indent, 'r' => :return }
- TYPES =
Mapping between prompt types and characters used to represent them in the prompt
{'n' => :normal, 's' => :string, 'c' => :statement, 'i' => :indent, 'r' => :return }
- PROMPTS =
Mapping between prompt names used by IRB and characters used to represent them in the prompt
{:PROMPT_I => 'n', :PROMPT_N => 'i', :PROMPT_S => 's', :PROMPT_C => 'c', :RETURN => 'r'}
Instance Attribute Summary (collapse)
-
- ({Symbol=>String}) prompts
readonly
The prompt to be used in IRB.
Instance Method Summary (collapse)
- - (Object) add_prompt(str, type)
-
- (PromptMatcher) initialize(id, prompts)
constructor
A new instance of PromptMatcher.
-
- (IrbLine?) match(str)
Checks whether a string begins with a prompt.
Constructor Details
- (PromptMatcher) initialize(id, prompts)
A new instance of PromptMatcher
34 35 36 37 38 39 40 |
# File 'plugins/irb/irb_controller.rb', line 34 def initialize id, prompts @id = id @prompts = {} prompts.each_pair do |k, v| @prompts[k] = "quirb:#{@id}:#{v}:quirb:#{@id}:#{PROMPTS[k]}:" end end |
Instance Attribute Details
Instance Method Details
- (Object) add_prompt(str, type)
TODO:
remove this
61 62 63 |
# File 'plugins/irb/irb_controller.rb', line 61 def add_prompt str, type "quirb:#{@id}:#{@prompts[type]}:quirb:#{@id}:#{MODES.invert[type]}:" << str end |
- (IrbLine?) match(str)
Checks whether a string begins with a prompt
49 50 51 52 53 54 55 56 57 58 |
# File 'plugins/irb/irb_controller.rb', line 49 def match str res = str.split "quirb:#{@id}:", 3 return if !res or !res[0].empty? or res.size < 3 res[1].slice! -1 #removes an ending : letter, sep, line = res[2].partition ':' type = TYPES[letter] if type then IrbLine.new type, line, res[1] else nil end end |