Sha256: 589ec39c45b6d28ca343c7dd96b16e6391b59237afdd28a00124e72587a10c81

Contents?: true

Size: 555 Bytes

Versions: 5

Compression:

Stored size: 555 Bytes

Contents

# frozen_string_literal: true

module Telegram
  module Bot
    module Types
      module Compactable
        def to_compact_hash
          attributes.dup.delete_if { |_, v| v.nil? }.to_h do |key, value|
            value =
              if value.respond_to?(:to_compact_hash)
                value.to_compact_hash
              else
                value
              end

            [key, value]
          end
        end

        def to_json(*args)
          to_compact_hash.select { |_, v| v }.to_json(*args)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
telegram-bot-ruby-1.0.0 lib/telegram/bot/types/compactable.rb
telegram-bot-ruby-1.0.0.rc1 lib/telegram/bot/types/compactable.rb
telegram-bot-ruby-1.0.0.pre lib/telegram/bot/types/compactable.rb
telegram-bot-ruby-0.23.0 lib/telegram/bot/types/compactable.rb
telegram-bot-ruby-0.22.0 lib/telegram/bot/types/compactable.rb