module Telegram module Params class ChatComponent attr_reader :id, :type, :title, :username, :first_name, :last_name, :all_members_are_administrators, :photo, :description, :invite_link, :pinned_message, :sticker_set_name, :can_set_sticker_set def initialize(params) return if params.blank? chat_params = chat_params_permit_from(params) @id = chat_params[:id] @type = chat_params[:type] @title = chat_params[:title] @username = chat_params[:username] @first_name = chat_params[:first_name] @last_name = chat_params[:last_name] @all_members_are_administrators = chat_params[:all_members_are_administrators] @photo = chat_params[:photo] @description = chat_params[:description] @invite_link = chat_params[:invite_link] @pinned_message = chat_params[:pinned_message] @sticker_set_name = chat_params[:sticker_set_name] @can_set_sticker_set = chat_params[:can_set_sticker_set] end def nil? self.instance_variables.map{ |attribute| self.instance_variable_get(attribute) } .map(&:nil?) .reduce(:&) end private def chat_params_permit_from(params) params.permit( :id, :type, :title, :username, :first_name, :last_name, :all_members_are_administrators, :photo, :description, :invite_link, :pinned_message, :sticker_set_name, :can_set_sticker_set ) end end end end