Sha256: 35c1ddb92ed5d51a447a777ff4becf69288b626ca19867973219046561a1fca1

Contents?: true

Size: 559 Bytes

Versions: 6

Compression:

Stored size: 559 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? }.map do |key, value|
            value =
              if value.respond_to?(:to_compact_hash)
                value.to_compact_hash
              else
                value
              end

            [key, value]
          end.to_h
        end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
telegram-bot-ruby-0.21.1 lib/telegram/bot/types/compactable.rb
telegram-bot-ruby-0.21.0 lib/telegram/bot/types/compactable.rb
telegram-bot-ruby-0.20.0 lib/telegram/bot/types/compactable.rb
telegram-bot-ruby-0.19.2 lib/telegram/bot/types/compactable.rb
telegram-bot-ruby-0.19.1 lib/telegram/bot/types/compactable.rb
telegram-bot-ruby-0.19.0 lib/telegram/bot/types/compactable.rb