Sha256: 37c3f34de42acc34400399cb5d62453a0c267ff19a72b4f142ee73d74c0f4bc4

Contents?: true

Size: 650 Bytes

Versions: 9

Compression:

Stored size: 650 Bytes

Contents

# frozen_string_literal: true

module LightspeedRestaurantClient
  class Base
    def initialize(data = {})
      convert_to_obj(data)
    end

    def attributes
      instance_variables.each_with_object({}) do |instance_variable, h|
        h[instance_variable[1..instance_variable.length]] = instance_variable_get(instance_variable)
      end
    end

    def to_json
      attributes.to_json
    end

    private

    def convert_to_obj(hash)
      hash.each do |key, value|
        self.class.send(:attr_accessor, key)
        instance_variable_set("@#{key}", value)
        convert_to_obj(value) if value.is_a? Hash
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lightspeed_restaurant-3.5.0 lib/lightspeed_restaurant/base.rb
lightspeed_restaurant-3.3.3 lib/lightspeed_restaurant/base.rb
lightspeed_restaurant-3.3.2 lib/lightspeed_restaurant/base.rb
lightspeed_restaurant-3.3.1 lib/lightspeed_restaurant/base.rb
lightspeed_restaurant-3.3.0 lib/lightspeed_restaurant/base.rb
lightspeed_restaurant-3.2.0 lib/lightspeed_restaurant/base.rb
lightspeed_restaurant-3.1.0 lib/lightspeed_restaurant/base.rb
lightspeed_restaurant-3.0.0 lib/lightspeed_restaurant/base.rb
lightspeed_restaurant-2.0.0 lib/lightspeed_restaurant/base.rb