Class: PlayerSetHistory::Player
- Inherits:
-
Object
- Object
- PlayerSetHistory::Player
- Defined in:
- lib/player_set_history/player.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#country ⇒ Object
Returns the value of attribute country.
-
#discord ⇒ Object
Returns the value of attribute discord.
-
#player_id ⇒ Object
Returns the value of attribute player_id.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#pronoun ⇒ Object
Returns the value of attribute pronoun.
-
#sets ⇒ Object
Returns the value of attribute sets.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#state ⇒ Object
Returns the value of attribute state.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#twitch ⇒ Object
Returns the value of attribute twitch.
-
#twitter ⇒ Object
Returns the value of attribute twitter.
Class Method Summary collapse
- .all ⇒ Object
- .create_from_json(user_hash) ⇒ Object
- .create_from_tag(prefix: "", tag:) ⇒ Object
- .find_or_create_from_slug(slug, importer) ⇒ Object
- .find_or_create_from_tag(tag:, prefix: "") ⇒ Object
Instance Method Summary collapse
- #add_player_attributes(attributes) ⇒ Object
- #get_all_sets ⇒ Object
- #get_all_sets_vs_player(player_tag) ⇒ Object
-
#initialize(attributes) ⇒ Player
constructor
A new instance of Player.
Constructor Details
#initialize(attributes) ⇒ Player
Returns a new instance of Player.
5 6 7 8 |
# File 'lib/player_set_history/player.rb', line 5 def initialize(attributes) attributes.each {|key, value| self.send(("#{key}="), value)} @@all << self end |
Instance Attribute Details
#country ⇒ Object
Returns the value of attribute country.
2 3 4 |
# File 'lib/player_set_history/player.rb', line 2 def country @country end |
#discord ⇒ Object
Returns the value of attribute discord.
2 3 4 |
# File 'lib/player_set_history/player.rb', line 2 def discord @discord end |
#player_id ⇒ Object
Returns the value of attribute player_id.
2 3 4 |
# File 'lib/player_set_history/player.rb', line 2 def player_id @player_id end |
#prefix ⇒ Object
Returns the value of attribute prefix.
2 3 4 |
# File 'lib/player_set_history/player.rb', line 2 def prefix @prefix end |
#pronoun ⇒ Object
Returns the value of attribute pronoun.
2 3 4 |
# File 'lib/player_set_history/player.rb', line 2 def pronoun @pronoun end |
#sets ⇒ Object
Returns the value of attribute sets.
2 3 4 |
# File 'lib/player_set_history/player.rb', line 2 def sets @sets end |
#slug ⇒ Object
Returns the value of attribute slug.
2 3 4 |
# File 'lib/player_set_history/player.rb', line 2 def slug @slug end |
#state ⇒ Object
Returns the value of attribute state.
2 3 4 |
# File 'lib/player_set_history/player.rb', line 2 def state @state end |
#tag ⇒ Object
Returns the value of attribute tag.
2 3 4 |
# File 'lib/player_set_history/player.rb', line 2 def tag @tag end |
#twitch ⇒ Object
Returns the value of attribute twitch.
2 3 4 |
# File 'lib/player_set_history/player.rb', line 2 def twitch @twitch end |
#twitter ⇒ Object
Returns the value of attribute twitter.
2 3 4 |
# File 'lib/player_set_history/player.rb', line 2 def twitter @twitter end |
Class Method Details
.all ⇒ Object
10 11 12 |
# File 'lib/player_set_history/player.rb', line 10 def self.all @@all end |
.create_from_json(user_hash) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/player_set_history/player.rb', line 18 def self.create_from_json(user_hash) attributes = { :pronoun => user_hash["genderPronoun"], :state => user_hash["location"]["state"], :country => user_hash["location"]["country"], :slug => user_hash["discriminator"], :player_id => user_hash["player"]["id"], :tag => user_hash["player"]["gamerTag"], :prefix => user_hash["player"]["prefix"], } # Links unless user_hash["authorizations"] == nil user_hash["authorizations"].each do |url| = "" = url["url"] if != nil if .include?("twitter") attributes[:twitter] = elsif .include?("discord") attributes[:discord] = elsif .include?("twitch") attributes[:twitch] = end end end end player = PlayerSetHistory::Player.new(attributes) return player end |
.create_from_tag(prefix: "", tag:) ⇒ Object
50 51 52 53 54 |
# File 'lib/player_set_history/player.rb', line 50 def self.create_from_tag(prefix: "", tag:) attributes = {:prefix => prefix, :tag => tag} player = PlayerSetHistory::Player.new(attributes) return player end |
.find_or_create_from_slug(slug, importer) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/player_set_history/player.rb', line 68 def self.find_or_create_from_slug(slug, importer) player_index = self.all.index {|x| x.slug == slug} if player_index == nil r_player = importer.import_user_from_sgg(slug) player = PlayerSetHistory::Player.create_from_json(r_player) else player = self.all[player_index] end return player end |
.find_or_create_from_tag(tag:, prefix: "") ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/player_set_history/player.rb', line 56 def self.find_or_create_from_tag(tag: , prefix: "") player_index = self.all.index {|x| x.tag.downcase == tag.downcase} if player_index == nil player = PlayerSetHistory::Player.create_from_tag(tag: tag, prefix: prefix) else player = self.all[player_index] end return player end |
Instance Method Details
#add_player_attributes(attributes) ⇒ Object
14 15 16 |
# File 'lib/player_set_history/player.rb', line 14 def add_player_attributes(attributes) attributes.each {|key, value| self.send(("#{key}="), value)} end |
#get_all_sets ⇒ Object
81 82 83 84 85 86 |
# File 'lib/player_set_history/player.rb', line 81 def get_all_sets sets = PlayerSetHistory::Set.all.select do |set| set.players.include?(self) end return sets end |
#get_all_sets_vs_player(player_tag) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/player_set_history/player.rb', line 88 def get_all_sets_vs_player (player_tag) sets = self.get_all_sets.select do |set| set.score.downcase.include?(player_tag.downcase) end return sets end |