Sha256: 8a2c7ef3b3f4430d5104f1d44aa8b0d7eb19b44716d629c8e333ed7da9bed664

Contents?: true

Size: 475 Bytes

Versions: 5

Compression:

Stored size: 475 Bytes

Contents

module Bitso
  module Helper
    def self.parse_objects!(string, klass)
      # If Bitso returned nothing (which it does if the results yield empty) 'cast' it to an array
      string = "[]" if string == ""

      objects = JSON.parse(string)
      objects.collect do |t_json|
        parse_object!(t_json, klass)
      end
    end

    def self.parse_object!(object, klass)
      object = JSON.parse(object) if object.is_a? String

      klass.new(object)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bitso-0.1.5 lib/bitso/helper.rb
bitso-0.1.4 lib/bitso/helper.rb
bitso-0.1.3 lib/bitso/helper.rb
bitso-0.1.2 lib/bitso/helper.rb
bitso-0.1.1 lib/bitso/helper.rb