class PlayerSetHistory::Player

Attributes

country[RW]
discord[RW]
player_id[RW]
prefix[RW]
pronoun[RW]
sets[RW]
slug[RW]
state[RW]
tag[RW]
twitch[RW]
twitter[RW]

Public Class Methods

all() click to toggle source
# File lib/player_set_history/player.rb, line 10
def self.all
  @@all
end
create_from_json(user_hash) click to toggle source
# 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|
      
      social = ""
      social = url["url"]
      
      if social != nil
        if social.include?("twitter")
          attributes[:twitter] = social
        elsif social.include?("discord")
          attributes[:discord] = social
        elsif social.include?("twitch")
          attributes[:twitch] = social
        end
      end
    end
  end
  player = PlayerSetHistory::Player.new(attributes)
  return player
end
create_from_tag(prefix: "", tag:) click to toggle source
# 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) click to toggle source
# 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: "") click to toggle source
# 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
new(attributes) click to toggle source
# File lib/player_set_history/player.rb, line 5
def initialize(attributes)
  attributes.each {|key, value| self.send(("#{key}="), value)} 
  @@all << self
end

Public Instance Methods

add_player_attributes(attributes) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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