Class: Ruber::IRB::IrbLine

Inherits:
Object show all
Defined in:
plugins/irb/irb_controller.rb,
plugins/irb/irb_controller.rb,
plugins/irb/irb_controller.rb,
plugins/irb/irb_controller.rb

Overview

A parsed line from IRB

It contains information about the prompt for the line, the text of the line and the type and category of prompt

Constant Summary

CATEGORIES =

The category corresponding to each line type

{
  :output => :output, 
  :return => :output,
  :normal => :input,
  :string => :input,
  :statement => :input,
  :indent => :input
}

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (IrbLine) initialize(type, text, prompt)

A new instance of IrbLine

Parameters:

  • type (Symbol)

    the type of the line. It can be: :output, :return, :normal, :string, :statement or :indent

  • text (String)

    the text of the line

  • the (String)

    text of the prompt



110
111
112
113
114
115
116
# File 'plugins/irb/irb_controller.rb', line 110

def initialize type, text, prompt
  @text = text
  @type = type
  @prompt = prompt
  @full_text = @prompt + @text
  @category = (type == :return or type == :output) ? :output : :input
end

Instance Attribute Details

- (Symbol) category (readonly)

The category of the line (basing on the prompt #type). It is :output if the prompt type is :output or :return and :input otherwise

Returns:

  • (Symbol)

    the category of the line (basing on the prompt #type). It is :output if the prompt type is :output or :return and :input otherwise



87
88
89
# File 'plugins/irb/irb_controller.rb', line 87

def category
  @category
end

- (String) full_text (readonly)

The full text of the line, made from the IRB prompt and the line contents

Returns:

  • (String)

    the full text of the line, made from the IRB prompt and the line contents



94
95
96
# File 'plugins/irb/irb_controller.rb', line 94

def full_text
  @full_text
end

- (String) prompt (readonly)

The text of the prompt

Returns:

  • (String)

    the text of the prompt



90
91
92
# File 'plugins/irb/irb_controller.rb', line 90

def prompt
  @prompt
end

- (String) text (readonly)

The content of the line

Returns:

  • (String)

    the content of the line



83
84
85
# File 'plugins/irb/irb_controller.rb', line 83

def text
  @text
end

- (Symbol) type (readonly)

The type of line. It can be:

  • :output if there’s no prompt
  • :return if the line starts with a :RETURN prompt
  • :normal if the line starts with a :PROMPT_I prompt
  • :string if the line starts with a :PROMPT_S prompt
  • :statement if the line starts with a :PROMPT_C prompt
  • :indent if the line starts with a :PROMPT_N prompt

Returns:

  • (Symbol)

    the type of line. It can be:

    • :output if there’s no prompt
    • :return if the line starts with a :RETURN prompt
    • :normal if the line starts with a :PROMPT_I prompt
    • :string if the line starts with a :PROMPT_S prompt
    • :statement if the line starts with a :PROMPT_C prompt
    • :indent if the line starts with a :PROMPT_N prompt


80
81
82
# File 'plugins/irb/irb_controller.rb', line 80

def type
  @type
end

Instance Method Details

- (Boolean) same_category_as?(other)

Returns:

  • (Boolean)


79
80
81
82
# File 'plugins/irb/irb_controller.rb', line 79

def same_category_as? other
  other = other.type unless other.is_a? Symbol
  CATEGORIES[@type] == CATEGORIES[other]
end