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?, #hash

Constructor Details

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

Returns a new instance of Member.



120
121
122
123
124
125
126
127
128
# File 'lib/discorb/application.rb', line 120

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.



102
103
104
# File 'lib/discorb/application.rb', line 102

def membership_state
  @membership_state
end

#permissions -> Array<Permissions> (readonly)

Note:

This always return :*.

Returns The permissions of the member.

Returns:

  • (Array<Permissions>)

    The permissions of the member.



106
107
108
# File 'lib/discorb/application.rb', line 106

def permissions
  @permissions
end

#team_id -> Snowflake (readonly)

Returns The ID of member's team.

Returns:



100
101
102
# File 'lib/discorb/application.rb', line 100

def team_id
  @team_id
end

#user -> Discorb::User (readonly)

Returns The user.

Returns:



98
99
100
# File 'lib/discorb/application.rb', line 98

def user
  @user
end

Instance Method Details

#==(other) -> Object



146
147
148
# File 'lib/discorb/application.rb', line 146

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

#accepted? -> Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/discorb/application.rb', line 134

def accepted?
  @membership_state == :accepted
end

#inspect -> Object



138
139
140
# File 'lib/discorb/application.rb', line 138

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

#owner? -> Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/discorb/application.rb', line 142

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

#pending? -> Boolean

Returns:

  • (Boolean)


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

def pending?
  @membership_state == :invited
end