class Prettyp::Formatter::JSON::Python

Public Class Methods

check_requirement() click to toggle source
# File lib/prettyp/formatter/json/python.rb, line 10
def self.check_requirement
  !%x|which #{executeable}|.empty?
end
executeable() click to toggle source
# File lib/prettyp/formatter/json/python.rb, line 9
def self.executeable; 'python'; end
languages() click to toggle source
# File lib/prettyp/formatter/json/python.rb, line 5
def self.languages
  ['JSON']
end

Public Instance Methods

format(input, language) click to toggle source
# 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