Sha256: 947f7d1fd650282ce57855910179e4146a696552b959af6af4493e5326c369f2

Contents?: true

Size: 1.13 KB

Versions: 83

Compression:

Stored size: 1.13 KB

Contents

class Pry
  class Command::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.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

      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.length)
      end
    end
  end
end

Version data entries

83 entries across 83 versions & 5 rubygems

Version Path
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/pry-0.9.12.6/lib/pry/commands/cat/input_expression_formatter.rb
pry-0.10.0.pre2 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.10.0.pre2-universal-mswin32 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.10.0.pre2-universal-mingw32 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.10.0.pre2-java lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.6 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.6-i386-mswin32 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.6-i386-mingw32 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.6-java lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.5 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.5-i386-mswin32 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.5-i386-mingw32 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.5-java lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.4 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.4-i386-mswin32 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.4-i386-mingw32 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.4-java lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.3 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.3-i386-mswin32 lib/pry/commands/cat/input_expression_formatter.rb
pry-0.9.12.3-i386-mingw32 lib/pry/commands/cat/input_expression_formatter.rb