Sha256: 4278ac8d3c9e3380cbf5046e04ad7d2e767c357aa3c15c0058c175b0ab141ba5

Contents?: true

Size: 537 Bytes

Versions: 8

Compression:

Stored size: 537 Bytes

Contents

require 'json'

class JSONMangler
  VERSION = '0.1.0'

  def initialize( json_data )
    ingest_json( json_data )
  end

  def valid
    !@json_obj.nil?
  end

  def prune( keys )
    if valid
      keys.each do |key|
        @json_obj.delete_if{|k, v| k == key }
      end
    end
  end

  def to_json
    if valid
      JSON.pretty_generate( @json_obj )
    else
      ""
    end
  end

 private

  def ingest_json( json_string )
    begin
      @json_obj = JSON.parse( json_string )
    rescue
      @json_obj = nil
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
leenookx-json-mangler-0.1.0 lib/json_mangler.rb
leenookx-json-mangler-0.1.1 lib/json-mangler/json_mangler.rb
leenookx-json-mangler-0.1.2 lib/json-mangler/json_mangler.rb
leenookx-json-mangler-0.2.1 lib/json-mangler/json_mangler.rb
leenookx-json-mangler-0.2.2 lib/json-mangler/json_mangler.rb
leenookx-json-mangler-0.2.3 lib/json-mangler/json_mangler.rb
leenookx-json-mangler-0.2.5 lib/json-mangler/json_mangler.rb
leenookx-json-mangler-0.2.6 lib/json-mangler/json_mangler.rb