Class: Pry::Command::Ls::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/pry/commands/ls/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pry_instance) ⇒ Formatter


10
11
12
13
14
# File 'lib/pry/commands/ls/formatter.rb', line 10

def initialize(pry_instance)
  @pry_instance = pry_instance
  @target = pry_instance.current_context
  @default_switch = nil
end

Instance Attribute Details

#grepObject (private)


49
50
51
# File 'lib/pry/commands/ls/formatter.rb', line 49

def grep
  @grep || proc { |x| x }
end

#pry_instanceObject (readonly)

Returns the value of attribute pry_instance


8
9
10
# File 'lib/pry/commands/ls/formatter.rb', line 8

def pry_instance
  @pry_instance
end

Instance Method Details

#color(type, str) ⇒ Object (private)


24
25
26
# File 'lib/pry/commands/ls/formatter.rb', line 24

def color(type, str)
  Pry::Helpers::Text.send pry_instance.config.ls.send("#{type}_color"), str
end

#correct_opts?Boolean (private)


41
42
43
# File 'lib/pry/commands/ls/formatter.rb', line 41

def correct_opts?
  @default_switch
end

#format_value(value) ⇒ Object (private)


37
38
39
# File 'lib/pry/commands/ls/formatter.rb', line 37

def format_value(value)
  Pry::ColorPrinter.pp(value, ''.dup)
end

#output_section(heading, body) ⇒ Object (private)

Add a new section to the output. Outputs nothing if the section would be empty.


30
31
32
33
34
35
# File 'lib/pry/commands/ls/formatter.rb', line 30

def output_section(heading, body)
  return '' if body.compact.empty?

  fancy_heading = Pry::Helpers::Text.bold(color(:heading, heading))
  Pry::Helpers.tablify_or_one_line(fancy_heading, body, @pry_instance)
end

#output_selfObject (private)

Raises:

  • (NotImplementedError)

45
46
47
# File 'lib/pry/commands/ls/formatter.rb', line 45

def output_self
  raise NotImplementedError
end

#write_outObject


16
17
18
19
20
# File 'lib/pry/commands/ls/formatter.rb', line 16

def write_out
  return false unless correct_opts?

  output_self
end