Class: Discorb::Application::Team::Member

Inherits:
DiscordModel show all
Defined in:
lib/discorb/application.rb

Overview

Represents a member of team.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DiscordModel

#eql?

Constructor Details

#initialize(client, team, data) -> Member

Returns a new instance of Member.



150
151
152
153
154
155
156
157
158
# File 'lib/discorb/application.rb', line 150

def initialize(client, team, data)
  @client = client
  @data = data
  @team = team
  @user = client.users[data[:user][:id]] || User.new(client, data[:user])
  @team_id = Snowflake.new(data[:team_id])
  @membership_state = self.class.membership_state[data[:membership_state]]
  @permissions = data[:permissions].map(&:to_sym)
end

Instance Attribute Details

#membership_state -> :invited, :accepted (readonly) Also known as: state

Returns The member's membership state.

Returns:

  • (:invited, :accepted)

    The member's membership state.



132
133
134
# File 'lib/discorb/application.rb', line 132

def membership_state
  @membership_state
end

#permissions -> Array<Symbol> (readonly)

Note:

This always return :*.

Returns The permissions of the member.

Returns:

  • (Array<Symbol>)

    The permissions of the member.



136
137
138
# File 'lib/discorb/application.rb', line 136

def permissions
  @permissions
end

#team_id -> Snowflake (readonly)

Returns The ID of member's team.

Returns:



130
131
132
# File 'lib/discorb/application.rb', line 130

def team_id
  @team_id
end

#user -> Discorb::User (readonly)

Returns The user.

Returns:



128
129
130
# File 'lib/discorb/application.rb', line 128

def user
  @user
end

Instance Method Details

#==(other) -> Object



176
177
178
# File 'lib/discorb/application.rb', line 176

def ==(other)
  super || @user == other
end

#accepted? -> Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/discorb/application.rb', line 164

def accepted?
  @membership_state == :accepted
end

#inspect -> Object



168
169
170
# File 'lib/discorb/application.rb', line 168

def inspect
  "#<#{self.class} id=#{@user.id}>"
end

#owner? -> Boolean

Returns:

  • (Boolean)


172
173
174
# File 'lib/discorb/application.rb', line 172

def owner?
  @team.owner_user_id == @user.id
end

#pending? -> Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/discorb/application.rb', line 160

def pending?
  @membership_state == :invited
end