Class: Prettyp::Formatter::JSON::Python

Inherits:
BaseFormatter show all
Defined in:
lib/prettyp/formatter/json/python.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseFormatter

#check_requirement, inherited, inherited_classes

Methods included from Logger

logger, #logger

Class Method Details

.check_requirementObject



10
11
12
# File 'lib/prettyp/formatter/json/python.rb', line 10

def self.check_requirement
  !%x|which #{executeable}|.empty?
end

.executeableObject



9
# File 'lib/prettyp/formatter/json/python.rb', line 9

def self.executeable; 'python'; end

.languagesObject



5
6
7
# File 'lib/prettyp/formatter/json/python.rb', line 5

def self.languages
  ['JSON']
end

Instance Method Details

#format(input, language) ⇒ Object



14
15
16
17
18
19
# File 'lib/prettyp/formatter/json/python.rb', line 14

def format input, language
  with_file(input) do |file|
    out = execute_command("cat #{file.path} | #{self.class.executeable} -m json.tool",
                          on_error: Proc.new { |output| raise FormatError, output })
  end
end