Sha256: 74fae87509c51971493416ff9987c1ca3c0976e43d5bdfa4b34308394eab45c2

Contents?: true

Size: 525 Bytes

Versions: 3

Compression:

Stored size: 525 Bytes

Contents

module Quickbooks
  module Payments
    # Basic JSON backed model
    class BasicModel
      attr_accessor :json

      def initialize(json = {})
        self.json = json

        json.each do |key, value|
          setter = "#{key}="
          send(setter, value) if respond_to?(setter)
        end
      end

      # Getters

      def to_json
        instance_variables.each_with_object({}) do |variable, sum|
          sum[variable[1..-1]] = instance_variable_get variable
        end.to_json
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
quickbooks-payments-0.0.9 lib/quickbooks-payments/basic_model.rb
quickbooks-payments-0.0.8 lib/quickbooks-payments/basic_model.rb
quickbooks-payments-0.0.7 lib/quickbooks-payments/basic_model.rb