Sha256: 4118dd660870529dc41e3aa1affb6dceb2c05c93ecd575c7dd6715529156bd69

Contents?: true

Size: 1.25 KB

Versions: 6842

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

class Pry
  class Command
    class Cat
      class InputExpressionFormatter < AbstractFormatter
        attr_accessor :input_expressions
        attr_accessor :opts

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

        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

        private

        def selected_input_items
          input_expressions[normalized_expression_range] || []
        end

        def numbered_input_items
          @numbered_input_items ||= normalized_expression_range.zip(selected_input_items)
            .reject { |_, s| s.nil? || s == "" }
        end

        def normalized_expression_range
          absolute_index_range(opts[:i], input_expressions.count)
        end
      end
    end
  end
end

Version data entries

6,842 entries across 6,837 versions & 33 rubygems

Version Path
ory-client-0.0.1.alpha77 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha76 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha75 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha74 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha73 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha72 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha71 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha70 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha69 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha68 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha67 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha66 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-oathkeeper-client-0.38.19.beta1 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-oathkeeper-client-0.38.18.beta1 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-oathkeeper-client-0.38.17.beta1 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
avalara_sdk-2.4.7 vendor/bundle/ruby/2.6.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha58 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha57 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha56 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb
ory-client-0.0.1.alpha55 vendor/bundle/ruby/2.5.0/gems/pry-0.13.1/lib/pry/commands/cat/input_expression_formatter.rb