Sha256: a5493dcb2522be540a0838584956cca805dff307ce29a2829b6ed6ac988e212e

Contents?: true

Size: 529 Bytes

Versions: 3

Compression:

Stored size: 529 Bytes

Contents

module Telegram
  module Bot
    module Types
      module Compactable
        def to_compact_hash
          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]
        end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
telegram-bot-ruby-0.18.0 lib/telegram/bot/types/compactable.rb
telegram-bot-ruby-0.17.0 lib/telegram/bot/types/compactable.rb
telegram-bot-ruby-0.16.0 lib/telegram/bot/types/compactable.rb