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

Inherits:
AbstractFormatter show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/commands/cat/input_expression_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::BaseHelpers

#colorize_code, #find_command, #heading, #highlight, #not_a_real_file?, #safe_send, #silence_warnings, #stagger_output, #use_ansi_codes?

Methods included from Helpers::CommandHelpers

#absolute_index_number, #absolute_index_range, #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.



10
11
12
13
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/commands/cat/input_expression_formatter.rb', line 10

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

Instance Attribute Details

#input_expressionsObject

Returns the value of attribute input_expressions.



7
8
9
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/commands/cat/input_expression_formatter.rb', line 7

def input_expressions
  @input_expressions
end

#optsObject

Returns the value of attribute opts.



8
9
10
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/commands/cat/input_expression_formatter.rb', line 8

def opts
  @opts
end

Instance Method Details

#formatObject

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pry-0.14.2/lib/pry/commands/cat/input_expression_formatter.rb', line 15

def format
  raise CommandError, "No input expressions!" if numbered_input_items.empty?

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

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