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_) ⇒ Formatter

Returns a new instance of Formatter



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

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

Instance Attribute Details

#_pry_Object (readonly)

Returns the value of attribute pry



5
6
7
# File 'lib/pry/commands/ls/formatter.rb', line 5

def _pry_
  @_pry_
end

#grepObject (private)



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

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

Instance Method Details

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



20
21
22
# File 'lib/pry/commands/ls/formatter.rb', line 20

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

#correct_opts?Boolean (private)

Returns:

  • (Boolean)


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

def correct_opts?
  @default_switch
end

#format_value(value) ⇒ Object (private)



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

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

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

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



26
27
28
29
30
# File 'lib/pry/commands/ls/formatter.rb', line 26

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

#output_selfObject (private)

Raises:

  • (NotImplementedError)


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

def output_self
  raise NotImplementedError
end

#write_outObject



13
14
15
16
# File 'lib/pry/commands/ls/formatter.rb', line 13

def write_out
  return false unless correct_opts?
  output_self
end