Sha256: b20e0cc133a5e23183c75ac8919071877747b7c4deea4e91ddd917a705b28c14

Contents?: true

Size: 547 Bytes

Versions: 4

Compression:

Stored size: 547 Bytes

Contents

module LightspeedRestaurant
  class Base
    def initialize(data = {})
      self.class.attributes.each do |attribute|
        data  = data.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
        value = ['N/A', ''].include?(data[attribute]) ? nil : data[attribute]
        send("#{attribute}=", value)
      end
    end

    def to_hash
      self.class.attributes.each_with_object({}) do |attribute, h|
        h[attribute] = instance_variable_get("@#{attribute}")
      end
    end

    def to_json
      to_hash.to_json
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lightspeed_restaurant-0.1.3 lib/lightspeed_restaurant/base.rb
lightspeed_restaurant-0.1.2 lib/lightspeed_restaurant/base.rb
lightspeed_restaurant-0.1.1 lib/lightspeed_restaurant/base.rb
lightspeed_restaurant-0.1.0 lib/lightspeed_restaurant/base.rb