Sha256: 040d8e10bf820e8d38892c0e581dfe112ecc881a4e3ef146bfda6de7e50a887d

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

module Telegram
  module Params
    class UserComponent
      attr_reader :id, :is_bot, :first_name, :last_name, :username, :language_code, :params

      def initialize(params)
        return if params.blank?
        user_params = user_params_permit_from(params)
        
        @id             = user_params[:id]
        @is_bot         = user_params[:is_bot]
        @first_name     = user_params[:first_name]
        @last_name      = user_params[:last_name]
        @username       = user_params[:username]
        @language_code  = user_params[:language_code]
      end

      def nil?
        self.instance_variables.map{ |attribute| self.instance_variable_get(attribute) }
                               .map(&:nil?)
                               .reduce(:&)
      end

      private

        def user_params_permit_from(params)
          params.permit(
                  :id,
                  :is_bot,
                  :first_name,
                  :last_name,
                  :username,
                  :language_code
                )
        end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tg-bot-0.0.5 lib/telegram/params/shared/user_component.rb
tg-bot-0.0.4 lib/telegram/params/shared/user_component.rb
tg-bot-0.0.3 lib/telegram/params/shared/user_component.rb
tg-bot-0.0.2 lib/telegram_bot/params/shared/user_component.rb
tg-bot-0.0.1 lib/telegram_bot/params/shared/user_component.rb