Sha256: 3234e4d31cb7c521350d5f956de7bbce4f7a1ac3dbf610ea56faae5339a20664

Contents?: true

Size: 750 Bytes

Versions: 3

Compression:

Stored size: 750 Bytes

Contents

# typed: strict
# frozen_string_literal: true

module LunchMoney
  # Namespace for data objects that represent objects returned from the API
  module Objects
    # Base data object for the objects returned and used when calling the LunchMoney API
    class Object
      sig { params(symbolize_keys: T::Boolean).returns(T::Hash[T.any(String, Symbol), T.untyped]) }
      def serialize(symbolize_keys: false)
        ivars = instance_variables

        output = {}

        ivars.each do |ivar|
          key = ivar.to_s.gsub("@", "")
          key = key.to_sym if symbolize_keys

          value = instance_variable_get(ivar)

          output[key] = value
        end

        output
      end

      delegate :to_h, to: :serialize
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lunchmoney-1.4.0 lib/lunchmoney/objects/object.rb
lunchmoney-1.2.0 lib/lunchmoney/objects/object.rb
lunchmoney-1.1.2 lib/lunchmoney/objects/object.rb