Class: Pry::Command::Cat::InputExpressionFormatter

Inherits:
AbstractFormatter show all
Defined in:
lib/pry/commands/cat/input_expression_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::BaseHelpers

colorize_code, command_dependencies_met?, find_command, heading, highlight, jruby?, jruby_19?, mri?, mri_19?, mri_20?, mri_21?, mri_2?, not_a_real_file?, rbx?, #safe_send, safe_send, silence_warnings, stagger_output, use_ansi_codes?, windows?, windows_ansi?

Methods included from Helpers::CommandHelpers

absolute_index_number, absolute_index_range, command_error, get_method_or_raise, internal_binding?, one_index_number, one_index_range, one_index_range_or_number, restrict_to_lines, set_file_and_dir_locals, temp_file, unindent

Methods included from Helpers::OptionsHelpers

method_object, method_options

Constructor Details

#initialize(input_expressions, opts) ⇒ InputExpressionFormatter

Returns a new instance of InputExpressionFormatter


7
8
9
10
# File 'lib/pry/commands/cat/input_expression_formatter.rb', line 7

def initialize(input_expressions, opts)
  @input_expressions = input_expressions
  @opts = opts
end

Instance Attribute Details

#input_expressionsObject

Returns the value of attribute input_expressions


4
5
6
# File 'lib/pry/commands/cat/input_expression_formatter.rb', line 4

def input_expressions
  @input_expressions
end

#optsObject

Returns the value of attribute opts


5
6
7
# File 'lib/pry/commands/cat/input_expression_formatter.rb', line 5

def opts
  @opts
end

Instance Method Details

#formatObject

Raises:


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pry/commands/cat/input_expression_formatter.rb', line 12

def format
  raise CommandError, "No input expressions!" if numbered_input_items.length < 1

  if numbered_input_items.length > 1
    content = ""
    numbered_input_items.each do |i, s|
      content << "#{Helpers::Text.bold(i.to_s)}:\n" << decorate(Pry::Code(s).with_indentation(2)).to_s
    end

    content
  else
    decorate(Pry::Code(selected_input_items.first))
  end
end