class Pry::Command::Cat::InputExpressionFormatter

Attributes

input_expressions[RW]
opts[RW]

Public Class Methods

new(input_expressions, opts) click to toggle source
# File lib/pry/commands/cat/input_expression_formatter.rb, line 7
def initialize(input_expressions, opts)
  @input_expressions = input_expressions
  @opts = opts
end

Public Instance Methods

format() click to toggle source
# 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)).to_s
  end
end

Private Instance Methods

normalized_expression_range() click to toggle source
# File lib/pry/commands/cat/input_expression_formatter.rb, line 38
def normalized_expression_range
  absolute_index_range(opts[:i], input_expressions.length)
end
numbered_input_items() click to toggle source
# File lib/pry/commands/cat/input_expression_formatter.rb, line 33
def numbered_input_items
  @numbered_input_items ||= normalized_expression_range.zip(selected_input_items).
    reject { |_, s| s.nil? || s == "" }
end
selected_input_items() click to toggle source
# File lib/pry/commands/cat/input_expression_formatter.rb, line 29
def selected_input_items
  input_expressions[normalized_expression_range] || []
end